<!DOCTYPE html>
<html>
  <!-- meta/link... -->
  



<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
  <!-- Global site tag (gtag.js) - Google Analytics -->


  <title>Docker | YY&#39;s Blog</title>

  <link rel="icon" type="image/jpeg" href="/medias/favicon.jpg">
  <link rel="stylesheet" href="https://at.alicdn.com/t/font_1911880_c1nvbyezg17.css">
  <link href="https://unpkg.com/@fortawesome/fontawesome-free/css/all.min.css" rel="stylesheet">
  <link href="/js/swiper/swiper@5.4.1.min.css" rel="stylesheet">
  
  
  
  
<link rel="stylesheet" href="/css/animate.min.css">

  
<link rel="stylesheet" href="/css/style.css">

  
  
    
<link rel="stylesheet" href="/js/fancybox/jquery.fancybox.min.css">

  
  
    
<link rel="stylesheet" href="/js/shareJs/share.min.css">

  
  <style>
        @media (max-width: 992px) {
            #waifu {
                display: none;
            }
        }
    </style>
    <script src="//cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>
    <link href="//cdn.bootcss.com/pace/1.0.2/themes/pink/pace-theme-flash.css" rel="stylesheet">

    
        <script src="/js/valine/index.js"></script>
    

    <!-- import link -->
    
        
            
        
            
        
    
    <!-- import script -->
    
        
            <script>function blog_time() {window.setTimeout(blog_time,1000);const now = new Date();const copyrightTime = now.getFullYear();			display_copyright_time.innerHTML = " "+copyrightTime;}blog_time();</script>
        
            <script>function blog_live_time() {window.setTimeout(blog_live_time, 1000);const start = new Date('2020-10-01T00:00:00');const now = new Date();const timeDiff = (now.getTime() - start.getTime());					  const msPerMinute = 60 * 1000;					  const msPerHour = 60 * msPerMinute;					  const msPerDay = 24 * msPerHour;					  const passDay = Math.floor(timeDiff / msPerDay);					  const passHour = Math.floor((timeDiff % msPerDay) / 60 / 60 / 1000);					  const passMinute = Math.floor((timeDiff % msPerHour) / 60 / 1000);const passSecond = Math.floor((timeDiff % msPerMinute) / 1000);display_live_time.innerHTML = " " + passDay + " 天 " + passHour + " 小时 " + passMinute + " 分 " + passSecond + " 秒";}blog_live_time();</script>
        
    

    <!-- import daovoice -->
    

        <script>(function (i, s, o, g, r, a, m) {
            i['DaoVoiceObject'] = r;
            i[r] = i[r] ||
              function () {
                (i[r].q = i[r].q || []).push(arguments);
              };
            i[r].l = 1 * new Date();
            a = s.createElement(o);
            m = s.getElementsByTagName(o)[0];
            a.async = 1;
            a.src = g;
            a.charset = 'utf-8';
            m.parentNode.insertBefore(a, m);
          })(window, document, 'script', ('https:' === document.location.protocol ? 'https:' : 'http:') + "//widget.daovoice.io/widget/5a027b89.js", 'daovoice');
          daovoice('init', {
            app_id: "5a027b89",
          });
          daovoice('update');
        </script>
      
    
<meta name="generator" content="Hexo 5.4.0"></head>

  
  <!-- 依赖于jquery和vue -->
  
    
<script src="https://unpkg.com/jquery@3.5.1/dist/jquery.min.js"></script>

  

  
    
<script src="https://unpkg.com/vue@2.6.11/dist/vue.min.js"></script>

  
  
  <body>
    <!-- 预加载动画 -->
    <!-- 页面预加载动画 -->

<div id='loader'>
  <link rel="stylesheet" href="/js/loaded/index.css" >
  <div class="loading-left-bg"></div>
  <div class="loading-right-bg"></div>
  <div class="spinner-box">
    <div class="configure-border-1">
      <div class="configure-core"></div>
    </div>
    <div class="configure-border-2">
      <div class="configure-core"></div>
    </div>
    <div class="loading-word">加载中...</div>
  </div>
</div>

<script>
  var endLoading = function () {
    document.body.style.overflow = 'auto';
    document.getElementById('loader').classList.add("loading");
  }
  window.addEventListener('DOMContentLoaded',endLoading);
  
</script>

    
    <!-- 判断是否为暗黑风格 -->
    <!-- 判断是否为黑夜模式 -->
<script>
  let isDark = JSON.parse(localStorage.getItem('dark')) || JSON.parse('false');

  if (isDark) {
    $(document.body).addClass('darkModel');
  }
</script>

    <!-- 需要在上面加载的js -->
    <script>
  function loadScript(src, cb) {
    return new Promise(resolve => {
      setTimeout(function () {
        var HEAD = document.getElementsByTagName("head")[0] || document.documentElement;
        var script = document.createElement("script");
        script.setAttribute("type", "text/javascript");
        if (cb) {
          if (JSON.stringify(cb)) {
            for (let p in cb) {
              if (p == "onload") {
                script[p] = () => {
                  cb[p]()
                  resolve()
                }
              } else {
                script[p] = cb[p]
                script.onload = resolve
              }
            }
          } else {
            script.onload = () => {
              cb()
              resolve()
            };
          }
        } else {
          script.onload = resolve
        }
        script.setAttribute("src", src);
        HEAD.appendChild(script);
      });
    });
  }

  //https://github.com/filamentgroup/loadCSS
  var loadCSS = function (href, before, media, attributes) {
    return new Promise(resolve => {
      setTimeout(function () {
        var link = document.createElement('link');
        link.rel = "stylesheet";
        link.href = src;
        link.onload = resolve;
        document.getElementsByTagName("head")[0].appendChild(link);
      });
    });
  };

</script> 

<!-- 轮播图所需要的js -->
<script src="/js/swiper/swiper.min.js"></script>
<script src="/js/swiper/vue-awesome-swiper.js"></script>
<script src="/js/swiper/swiper.animate1.0.3.min.js"></script>

<script type="text/javascript">
  Vue.use(window.VueAwesomeSwiper)
</script>


  <script src="/js/vue-typed-js/index.js"></script>


<!-- 首页的公告滚动插件的js需要重新加载 -->
<script src="/js/vue-seamless-scroll/index.js"></script>

<!-- 打字机效果js -->
<script src="https://unpkg.com/typed.js@2.0.11"></script>


    <div id="safearea">
      <main class="main" id="pjax-container">
        <!-- 头部导航 -->
        
<header class="header   " 
  id="navHeader"
  style="position: fixed;
  left: 0; top: 0; z-index: 10;width: 100%;"
>
  <div class="header-content">
    <div class="bars">
      <div id="appDrawer" class="sidebar-image">
  <div class="drawer-box-icon">
    <i class="fas fa-bars" aria-hidden="true" @click="showDialogDrawer"></i>
  </div>
  
  <transition name="fade">
    <div class="drawer-box_mask" v-cloak style="display: none;" v-show="visible" @click.self="cancelDialogDrawer">
    </div>
  </transition>
  <div class="drawer-box" :class="{'active': visible}">
    <div class="drawer-box-head bg-color">
      <img class="drawer-box-head_logo lazyload placeholder" src="/medias/logo.png" class="lazyload placeholder" data-srcset="/medias/logo.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="logo">
      <h3 class="drawer-box-head_title">YY&#39;s Blog</h3>
      <h5 class="drawer-box-head_desc">三十年河东，三十年河西，莫欺少年穷！</h5>
    </div>
    
    <div class="drawer-box-content">
      <ul class="drawer-box-content_menu">
        
          
            <li class="drawer-box-content_item" style="position: relative;">
              
                <a href="/" class="drawer-menu-item-link">
                  
                    <i class="fa fa-home" aria-hidden="true"></i>
                  
                  <span class="name">首页</span>
                </a>
              
            </li>
          
            <li class="drawer-box-content_item" style="position: relative;">
              
                <a href="/archives" class="drawer-menu-item-link">
                  
                    <i class="fa fa-archive" aria-hidden="true"></i>
                  
                  <span class="name">归档</span>
                </a>
              
            </li>
          
            <li class="drawer-box-content_item" style="position: relative;">
              
                <a href="/tags" class="drawer-menu-item-link">
                  
                    <i class="fa fa-tags" aria-hidden="true"></i>
                  
                  <span class="name">标签</span>
                </a>
              
            </li>
          
            <li class="drawer-box-content_item" style="position: relative;">
              
                <a href="/categories" class="drawer-menu-item-link">
                  
                    <i class="fa fa-bookmark" aria-hidden="true"></i>
                  
                  <span class="name">分类</span>
                </a>
              
            </li>
          
            <li class="drawer-box-content_item" style="position: relative;">
              
                <a href="/about" class="drawer-menu-item-link">
                  
                    <i class="fa fa-user" aria-hidden="true"></i>
                  
                  <span class="name">关于</span>
                </a>
              
            </li>
          
            <li class="drawer-box-content_item" style="position: relative;">
              
                <a href="/comments" class="drawer-menu-item-link">
                  
                    <i class="fa fa-comments" aria-hidden="true"></i>
                  
                  <span class="name">留言</span>
                </a>
              
            </li>
          
            <li class="drawer-box-content_item" style="position: relative;">
              
                <a href="/friends" class="drawer-menu-item-link">
                  
                    <i class="fa fa-book" aria-hidden="true"></i>
                  
                  <span class="name">友情链接</span>
                </a>
              
            </li>
          
            <li class="drawer-box-content_item" style="position: relative;">
              
                <a href="/love" class="drawer-menu-item-link">
                  
                    <i class="fa fa-heart" aria-hidden="true"></i>
                  
                  <span class="name">Love</span>
                </a>
              
            </li>
          
            <li class="drawer-box-content_item" style="position: relative;">
              
                <a href="javascript:;" class="drawer-menu-item-link has-children" @click="openOrCloseMenu(8)">
                  <span>
                    
                      <i class="fa fa-link"></i>
                    
                    <span class="name">更多</span>
                  </span>
                  <i class="fas fa-chevron-left arrow " :class="{'icon-rotate': isOpen(8)}" aria-hidden="true"></i>
                </a>
                <ul class="drawer-sub-menu" v-if="isOpen(8)">
                  
                  <li>
                    <a href="/gallery">
                      
                      <i class="fa fa-music" style="margin-top: -20px;"></i>
                      
                      <span>图库</span>
                    </a>
                  </li>
                  
                  <li>
                    <a href="/me">
                      
                      <i class="fa fa-user" style="margin-top: -20px;"></i>
                      
                      <span>关于我</span>
                    </a>
                  </li>
                  
                  <li>
                    <a href="/resources">
                      
                      <i class="fa fa-film" style="margin-top: -20px;"></i>
                      
                      <span>资源</span>
                    </a>
                  </li>
                  
                  <li>
                    <a target="_blank" rel="noopener" href="http://baidu.com">
                      
                      <i class="fa fa-wifi" style="margin-top: -20px;"></i>
                      
                      <span>百度</span>
                    </a>
                  </li>
                  
                </ul>
              
            </li>
          
        
        
          <li class="drawer-box-content_item">
            <a target="_blank" rel="noopener" href="https://gitee.com/yangyang-linux">
              <i class="fas fa-github" aria-hidden="true"></i>
              <span>Github</span>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</div>

<script>
  var body = document.body || document.documentElement || window;
  var vm = new Vue({
    el: '#appDrawer',
    data: {
      visible: false,
      top: 0,
      openArr: [],
    },
    computed: {
    },
    mounted() {
    },
    methods: {
      isOpen(index) {
        if (this.openArr.includes(index)) {
          return true;
        } else {
          return false;
        }
      },
      openOrCloseMenu(curIndex) {
        const index = this.openArr.indexOf(curIndex);
        if (index !== -1) {
          this.openArr.splice(index, 1);
        } else {
          this.openArr.push(curIndex);
        }
      },
      showDialogDrawer() {
        this.visible = true;
        // 防止页面滚动，只能让弹框滚动
        this.top = $(document).scrollTop()
        body.style.cssText = 'width: 100%; height: 100%;overflow: hidden;';
      },
      cancelDialogDrawer() {
        this.visible = false;
        body.removeAttribute('style');
        $(document).scrollTop(this.top)
      }
    },
    created() {}
  })
</script>

    </div>
    <div class="blog-title" id="author-avatar">
      
        <div class="avatar">
          <img src="/medias/logo.png" class="lazyload placeholder" data-srcset="/medias/logo.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="logo">
        </div>
      
      <a href="/" class="logo">YY&#39;s Blog</a>
    </div>
    <nav class="navbar">
      <ul class="menu">
        
          
            <li class="menu-item" style="position: relative;">
              
                <a href="/" class="menu-item-link" title="首页">
                  
                    <i class="fa fa-home" aria-hidden="true"></i>
                  
                  <span class="name">首页</span>
                </a>
              
            </li>
          
            <li class="menu-item" style="position: relative;">
              
                <a href="/archives" class="menu-item-link" title="归档">
                  
                    <i class="fa fa-archive" aria-hidden="true"></i>
                  
                  <span class="name">归档</span>
                </a>
              
            </li>
          
            <li class="menu-item" style="position: relative;">
              
                <a href="/tags" class="menu-item-link" title="标签">
                  
                    <i class="fa fa-tags" aria-hidden="true"></i>
                  
                  <span class="name">标签</span>
                </a>
              
            </li>
          
            <li class="menu-item" style="position: relative;">
              
                <a href="/categories" class="menu-item-link" title="分类">
                  
                    <i class="fa fa-bookmark" aria-hidden="true"></i>
                  
                  <span class="name">分类</span>
                </a>
              
            </li>
          
            <li class="menu-item" style="position: relative;">
              
                <a href="/about" class="menu-item-link" title="关于">
                  
                    <i class="fa fa-user" aria-hidden="true"></i>
                  
                  <span class="name">关于</span>
                </a>
              
            </li>
          
            <li class="menu-item" style="position: relative;">
              
                <a href="/comments" class="menu-item-link" title="留言">
                  
                    <i class="fa fa-comments" aria-hidden="true"></i>
                  
                  <span class="name">留言</span>
                </a>
              
            </li>
          
            <li class="menu-item" style="position: relative;">
              
                <a href="/friends" class="menu-item-link" title="友情链接">
                  
                    <i class="fa fa-book" aria-hidden="true"></i>
                  
                  <span class="name">友情链接</span>
                </a>
              
            </li>
          
            <li class="menu-item" style="position: relative;">
              
                <a href="/love" class="menu-item-link" title="Love">
                  
                    <i class="fa fa-heart" aria-hidden="true"></i>
                  
                  <span class="name">Love</span>
                </a>
              
            </li>
          
            <li class="menu-item" style="position: relative;">
              
                <a href="javascript:;" class="menu-item-link" title="更多">
                  
                    <i class="fa fa-link"></i>
                  
                  <span class="name">更多</span>
                  <i class="fas fa-chevron-down arrow" aria-hidden="true"></i>
                </a>
                <ul class="sub-menu">
                  
                  <li>
                    <a href="/gallery">
                      
                      <i class="fa fa-music" style="margin-top: -20px;"></i>
                      
                      <span>图库</span>
                    </a>
                  </li>
                  
                  <li>
                    <a href="/me">
                      
                      <i class="fa fa-user" style="margin-top: -20px;"></i>
                      
                      <span>关于我</span>
                    </a>
                  </li>
                  
                  <li>
                    <a href="/resources">
                      
                      <i class="fa fa-film" style="margin-top: -20px;"></i>
                      
                      <span>资源</span>
                    </a>
                  </li>
                  
                  <li>
                    <a target="_blank" rel="noopener" href="http://baidu.com">
                      
                      <i class="fa fa-wifi" style="margin-top: -20px;"></i>
                      
                      <span>百度</span>
                    </a>
                  </li>
                  
                </ul>
              
            </li>
          
        
      </ul>
      
      
        <div id="appSearch">
  <div class="search"  @click="showDialog()"><i class="fas fa-search" aria-hidden="true"></i></div>
  <transition name="fade">
    <div class="message-box_wrapper" style="display: none;" v-cloak v-show="dialogVisible" @click.self="cancelDialogVisible()">
      <div class="message-box animated bounceInDown">
        <h2>
          <span>
            <i class="fas fa-search" aria-hidden="true"></i>
            <span class="title">本地搜索</span>
          </span>
          <i class="fas fa-times close" pointer style="float:right;" aria-hidden="true" @click.self="cancelDialogVisible()"></i>
        </h2>
        <form class="site-search-form">
          <input type="text"
            placeholder="请输入关键字"
            id="local-search-input" 
            @click="getSearchFile()"
            class="st-search-input"
            v-model="searchInput"
          />
        </form>
        <div class="result-wrapper">
          <div id="local-search-result" class="local-search-result-cls"></div>
        </div>
      </div>
    </div>
  </transition>
</div>
<script src="/js/local_search.js"></script>
<script>
  var body = document.body || document.documentElement || window;
  var vm = new Vue({
    el: '#appSearch',
    data: {
      dialogVisible: false,
      searchInput: '',
      top: 0,
    },
    computed: {
    },
    mounted() {
      window.addEventListener('pjax:complete', () => {
        this.cancelDialogVisible();
      })
    },
    methods: {
      showDialog() {
        this.dialogVisible = true;
        // 防止页面滚动，只能让弹框滚动
        this.top = $(document).scrollTop()
        body.style.cssText = 'overflow: hidden;';
      },
      getSearchFile() {
        if (!this.searchInput) {
          getSearchFile("/search.xml");
        }
      },
      cancelDialogVisible() {
        this.dialogVisible = false;
        body.removeAttribute('style');
        $(document).scrollTop(this.top)
      },
    },
    created() {}
  })
</script>
<!-- 解决刷新页面闪烁问题，可以在元素上添加display: none, 或者用vue.extend方法，详情：https://blog.csdn.net/qq_31393401/article/details/81017912 -->
<!-- 下面是搜索基本写法 -->
<!-- <script type="text/javascript" id="local.search.active">
  var inputArea = document.querySelector("#local-search-input");
  inputArea.onclick   = function(){ getSearchFile(); this.onclick = null }
  inputArea.onkeydown = function(){ if(event.keyCode == 13) return false }
</script> -->

      

    </nav>
  </div>
  
    <a target="_blank" rel="noopener" href="https://gitee.com/yangyang-linux" class="github-corner color-primary" aria-label="View source on GitHub"><svg width="60" height="60" viewBox="0 0 250 250" style="fill:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
  
  
    <div id="he-plugin-simple"></div>
    <script>
      WIDGET = {
        CONFIG: {
          "modules": "012",
          "background": 5,
          "tmpColor": "4A4A4A",
          "tmpSize": 16,
          "cityColor": "4A4A4A",
          "citySize": 16,
          "aqiSize": 16,
          "weatherIconSize": 24,
          "alertIconSize": 18,
          "padding": "10px 10px 10px 10px",
          "shadow": "1",
          "language": "auto",
          "borderRadius": 5,
          "fixed": "false",
          "vertical": "middle",
          "horizontal": "center",
          "key": "2784dd3fcb1e4f0f9a9b579bf69641f2"
        }
      }
    </script>
    <script src="https://widget.qweather.net/simple/static/js/he-simple-common.js?v=2.0"></script> 
    
</header>
        <!-- 内容区域 -->
        
 <!-- prismjs 代码高亮 -->
 


<div class="bg-dark-floor" style="position: fixed;left: 0;top: 0;width: 100%;height: 100%;z-index: -1;"></div>


  <!-- 文章详情页顶部图片和标题 -->




<div class="post-detail-header" id="thumbnail_canvas" style="background-repeat: no-repeat; background-size: cover; 
  background-position: center center;position: relative;background-image:url('/medias/1.jpg')">
  <div class="post-detail-header-mask"></div>
  <canvas id="header_canvas"style="position:absolute;bottom:0;pointer-events:none;"></canvas>
  
  <div class="post-detail-header_info-box">
    <div class="title-box">
      <span class="title">
        Docker
      </span>
    </div>
    
    
      
        <span class="post-detail-header_date">
          <i class="fas fa-calendar"></i> 发表于：2021-07-12 |
        </span>
      

      

      
        <div class="post-detail-header_wordcount">
          <span class="totalcount">
            <i class="fas fa-file-text-o"></i> 字数统计: 13k |
          </span>
  
          <span class="min2read">
            <i class="fas fa-clock"></i> 阅读时长: 61分钟 |
          </span>
  
          
            <span class="reading">
              <i class="fas fa-eye"></i> 阅读量：<span id="busuanzi_value_page_pv"></span>
            </span>
          
        </div>
      
    
  </div>
  
  
    <script src="/js/bubble/bubble.js"></script>
  
</div>





<div class="row justify-position" 
  style="padding-top: 0px;">
  <div class="main-content">
    <article class="post post-detail">
      <div class="post-content">
        <h2 id="Docker"><a href="#Docker" class="headerlink" title="Docker"></a>Docker</h2><blockquote>
<p> docker学习</p>
<ul>
<li><p>DOCKER概述;</p>
</li>
<li><p>DOCKER安装</p>
</li>
<li><p>DOCKER命令</p>
<ul>
<li><p>镜像命令</p>
</li>
<li><p>容器命令</p>
</li>
<li><p>操作命令</p>
</li>
<li><p>。。。</p>
</li>
</ul>
</li>
</ul>
<ul>
<li>Docker镜像</li>
<li>容器的数据卷</li>
<li>DockerFile</li>
<li>Docker⽹络原理</li>
<li>IDEA整合DOCKER</li>
<li>Docker Compose</li>
<li>Docker Swarm</li>
<li>CI\CD jenkins</li>
</ul>
</blockquote>
<h2 id="Docker概述"><a href="#Docker概述" class="headerlink" title="Docker概述"></a>Docker概述</h2><h4 id="Docker为什么会出现？"><a href="#Docker为什么会出现？" class="headerlink" title="Docker为什么会出现？"></a>Docker为什么会出现？</h4><p>⼀款产品，开发—–上线，两套环境！应⽤环境！应⽤配置！</p>
<p>开发——-运维。 问题：我在我的电脑上可以使⽤！版本更新，导致服务不可⽤！对于运维来说考验⼗分⼤！</p>
<p>开发即运维！！！</p>
<p>环境配置⼗分麻烦，每⼀个机器都要配置环境（集群Redis、ES、Hadoop。。。）！！费时费⼒！！</p>
<p>发布⼀个项⽬jar+(REdis Mysql jdk ES)，项⽬带上环境安装打包！！</p>
<p>之前在服务器配置⼀个应⽤的环境（REdis Mysql jdk ES Hadoop）,配置超麻烦，不能够跨平台！！</p>
<p>windows，连最后发布到linux</p>
<p>传统：开发jar打包， 运维来做</p>
<p>现在：开发打包部署上线，⼀套流程做完</p>
<p><em>java——apk—–发布(应⽤商店)—-张三使⽤apk——–安装即可⽤</em></p>
<p><em>java——jar(环境)——-打包项⽬带环境(镜像！)——–Docker仓库：商店———–下载我么发布的镜像直接运⾏即可</em></p>
<p><strong>Docker对于以上问题产⽣了⼀个解决⽅案</strong></p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/WKGGd0"><img src="https://z3.ax1x.com/2021/07/16/WKGGd0.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/16/WKGGd0.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="WKGGd0.png"></a></p>
<p>docker思想来⾃⼀个集装箱</p>
<p>JRE —-多个应⽤（端⼝冲突）——–因为原来都是交叉的</p>
<p>隔离：Docker核⼼思想！打包装箱！每个箱⼦都是互相隔离的</p>
<p><strong>⽔果 —–⽣化武器</strong></p>
<p>Docker通过隔离机制，可以将服务器利⽤到极致</p>
<p>本质：所有的技术都是因为出现⼀些问题才会出现的；</p>
<h4 id="Docker历史"><a href="#Docker历史" class="headerlink" title="Docker历史"></a>Docker历史</h4><p>2010 ，⼏个搞IT的年轻⼈，在美国成⽴了⼀家公司<code>dotcloud</code>,做⼀些pass的云计算服务,LXC(linux虚拟机)有关的容器技术</p>
<p>他们将⾃⼰的<strong>容器化技术</strong>命名就是Docker！</p>
<p>刚诞⽣的时候，没有引起⾏业的注意！！dotcloub，就活不下去！！</p>
<p>开源</p>
<p>2013年，Docker开源；</p>
<p>Docker越来越多的⼈发现了Docker的优点，每个⽉都会更新</p>
<p>2014年4⽉9⽇，Docker1.0发布</p>
<p>Docker这么⽕的原因？它相对虚拟机⼗分轻巧</p>
<p>在容器技术出现之前，我们都是使⽤虚拟机</p>
<p>虚拟机运⾏：在windows或者mac中安装⼀个虚拟机软件vmware，可以虚拟⼀台或多台电脑！占⽤内</p>
<p>存太⼤！笨重！</p>
<p>虚拟机也是属于虚拟化技术，Docker容器技术，也是⼀种虚拟化技术！</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">vm:linux centos(原⽣镜像)，隔离，就需要开启多个虚拟机 ！⼏个G 启动需要⼏分钟</span><br><span class="line">Docker:隔离，镜像(最核⼼的环境 4m+jdk+mysql)⼗分的⼩巧，运⾏镜像就可以了！⼩巧！⼏M 、KB 秒级启动</span><br></pre></td></tr></table></figure>

<p>到现在所有开发⼈员必须会</p>
<blockquote>
<p>聊聊Docker</p>
</blockquote>
<p>Docker是基于GO语⾔开发的 ！开源项⽬</p>
<p>官⽹：<a target="_blank" rel="noopener" href="https://www.docker.com/">https://www.docker.com</a></p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/WKG0y9"><img src="https://z3.ax1x.com/2021/07/16/WKG0y9.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/16/WKG0y9.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="WKG0y9.png"></a></p>
<p>⽂档地址：<a target="_blank" rel="noopener" href="https://docs.docker.com/">https://docs.docker.com</a> Docker的⽂档超级详细的！</p>
<p>仓库地址：<a target="_blank" rel="noopener" href="https://registry.hub.docker.com/">https://registry.hub.docker.com</a></p>
<h4 id="Docker能干嘛？"><a href="#Docker能干嘛？" class="headerlink" title="Docker能干嘛？"></a>Docker能干嘛？</h4><blockquote>
<p> 之前的虚拟机技术</p>
</blockquote>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/WKGBLR"><img src="https://z3.ax1x.com/2021/07/16/WKGBLR.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/16/WKGBLR.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="WKGBLR.png"></a></p>
<p><strong>虚拟机技术的缺点：</strong></p>
<ol>
<li><p> 占⽤资源⼗分多</p>
</li>
<li><p>冗余步骤⼗分多</p>
</li>
<li><p>启动很慢</p>
</li>
</ol>
<hr>
<blockquote>
<p>容器化技术</p>
</blockquote>
<p><strong>容器化技术不是模拟的完整的操作系统</strong></p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/WKGsdx"><img src="https://z3.ax1x.com/2021/07/16/WKGsdx.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/16/WKGsdx.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="WKGsdx.png"></a></p>
<p><strong>⽐较Docker和虚拟机技术的不同：</strong></p>
<ul>
<li>传统虚拟机，虚拟出⼀个硬件 ，运⾏⼀个完整的操作系统，然后在这个系统上安装和运⾏软件</li>
<li>容器的应⽤直接运⾏在宿主机的内容，容器是没有⾃⼰的内核，也没有虚拟我们的硬件，所以就轻便了</li>
<li>每个容器件恶事互相隔离的，每个容器内都有⼀个属于⾃⼰的⽂件系统</li>
</ul>
<hr>
<blockquote>
<p>DebOps(开发，运维)</p>
</blockquote>
<p><strong>更快速的交付和部署</strong></p>
<p>传统：⼀堆的帮助⽂档，安装程序</p>
<p>Docker：打包镜像，发布测试，⼀键运⾏</p>
<p><strong>更便捷的升级和扩缩容</strong></p>
<p>使⽤Docker之后，我们部署应⽤就和搭积⽊⼀样</p>
<p>项⽬打包为⼀个镜像，扩展 服务器A! 服务器B</p>
<p><strong>更简单的系统运维</strong></p>
<p>在容器化之后，我们的开发或测试环境,都是⾼度⼀致的</p>
<p><strong>更⾼效的计算机资源利⽤</strong></p>
<p>Docker 是内核级别的虚拟化 ，可以在物理机上运⾏很多的容器实例！服务器的性能可以被压榨到极致</p>
<h2 id="Docker安装"><a href="#Docker安装" class="headerlink" title="Docker安装"></a>Docker安装</h2><h4 id="Docker基本组成"><a href="#Docker基本组成" class="headerlink" title="Docker基本组成"></a>Docker基本组成</h4><p><a target="_blank" rel="noopener" href="https://imgtu.com/i/WKG2WD"><img src="https://z3.ax1x.com/2021/07/16/WKG2WD.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/16/WKG2WD.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="WKG2WD.png"></a></p>
<p><strong>镜像(image)：</strong></p>
<p>docker镜像就好⽐是⼀个模版，可以通过这个模版来创建⼀个容器服务，tomcat===&gt;run(运⾏起</p>
<p>来)===&gt;tomcat01容器(提供服务)，通过这个镜像可以创建多个容器(最终服务器运⾏，或者项⽬运⾏</p>
<p>就是在容器中的)</p>
<p><strong>容器（container）：</strong></p>
<p>Docker利⽤容器技术，独⽴运⾏⼀个或者⼀组应⽤，通过镜像创建的</p>
<p>启动，停⽌，删除，基本命令！</p>
<p>⽬前就可以把容器理解为简易的linux系统</p>
<p><strong>仓库（repository）：</strong></p>
<p>存放镜像的地⽅！</p>
<p>仓库分为公有仓库和私有仓库：</p>
<p>Docker Hub（默认是国外的）</p>
<p>阿⾥云。。。。都有容器服务（配置镜像加速）</p>
<h4 id="安装Docker"><a href="#安装Docker" class="headerlink" title="安装Docker"></a>安装Docker</h4><blockquote>
<p>环境准备</p>
</blockquote>
<ol>
<li><p>需要会⼀点点linux基础</p>
</li>
<li><p>Centos</p>
</li>
<li><p>使⽤xshell连接远程服务器操作</p>
</li>
</ol>
<blockquote>
<p>环境查看</p>
</blockquote>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 系统内核是3.10以上的</span></span><br><span class="line">[root@localhost ~]<span class="comment"># uname -r</span></span><br><span class="line">4.18.0-240.el8.x86_64</span><br><span class="line">[root@localhost ~]<span class="comment"># uname -r</span></span><br><span class="line">4.18.0-240.el8.x86_64</span><br><span class="line"><span class="comment"># 系统版本</span></span><br><span class="line">[root@localhost ~]<span class="comment"># cat /etc/os-release</span></span><br><span class="line">NAME=<span class="string">&quot;CentOS Linux&quot;</span></span><br><span class="line">VERSION=<span class="string">&quot;8&quot;</span></span><br><span class="line">ID=<span class="string">&quot;centos&quot;</span></span><br><span class="line">ID_LIKE=<span class="string">&quot;rhel fedora&quot;</span></span><br><span class="line">VERSION_ID=<span class="string">&quot;8&quot;</span></span><br><span class="line">PLATFORM_ID=<span class="string">&quot;platform:el8&quot;</span></span><br><span class="line">PRETTY_NAME=<span class="string">&quot;CentOS Linux 8&quot;</span></span><br><span class="line">ANSI_COLOR=<span class="string">&quot;0;31&quot;</span></span><br><span class="line">CPE_NAME=<span class="string">&quot;cpe:/o:centos:centos:8&quot;</span></span><br><span class="line">HOME_URL=<span class="string">&quot;https://centos.org/&quot;</span></span><br><span class="line">BUG_REPORT_URL=<span class="string">&quot;https://bugs.centos.org/&quot;</span></span><br><span class="line">CENTOS_MANTISBT_PROJECT=<span class="string">&quot;CentOS-8&quot;</span></span><br><span class="line">CENTOS_MANTISBT_PROJECT_VERSION=<span class="string">&quot;8&quot;</span></span><br></pre></td></tr></table></figure>

<blockquote>
<p>安装</p>
</blockquote>
<p>帮助⽂档：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 1.卸载旧的版本</span></span><br><span class="line">sudo yum remove docker \</span><br><span class="line"> docker-client \</span><br><span class="line"> docker-client-latest \</span><br><span class="line"> docker-common \</span><br><span class="line"> docker-latest \</span><br><span class="line"> docker-latest-logrotate \</span><br><span class="line"> docker-logrotate \</span><br><span class="line"> docker-engine</span><br><span class="line"><span class="meta">#</span><span class="bash"> 2.需要的安装包</span></span><br><span class="line">yum install -y yum-utils</span><br><span class="line"><span class="meta">#</span><span class="bash"> 3.设置镜像的仓库</span></span><br><span class="line">yum-config-manager \</span><br><span class="line"> --add-repo \</span><br><span class="line"> https://download.docker.com/linux/centos/docker-ce.repo #默认是从国外的！</span><br><span class="line"> </span><br><span class="line">yum-config-manager \</span><br><span class="line"> --add-repo \</span><br><span class="line"> http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo #推荐使⽤阿⾥</span><br><span class="line">云</span><br><span class="line"><span class="meta"> </span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 更新yum软件包索引：</span></span><br><span class="line">[root@localhost ~]# yum makecache </span><br><span class="line"><span class="meta">#</span><span class="bash"> 4.安装Docker相关的内容 docker-ce 社区 ee 企业版</span></span><br><span class="line">yum install docker-ce docker-ce-cli containerd.io</span><br><span class="line"><span class="meta">#</span><span class="bash"> 5.启动Docker</span></span><br><span class="line">systemctl start docker</span><br><span class="line"><span class="meta">#</span><span class="bash"> 6.使⽤docker version查看是否安装成功</span></span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/WKGWSe"><img src="https://z3.ax1x.com/2021/07/16/WKGWSe.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/16/WKGWSe.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="WKGWSe.png"></a></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 7.使⽤hello world</span></span><br><span class="line">docker run hello-world</span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/WKGhyd"><img src="https://z3.ax1x.com/2021/07/16/WKGhyd.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/16/WKGhyd.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="WKGhyd.png"></a></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 8.查看下载的hello-world镜像</span></span><br><span class="line">[root@localhost ~]# docker images</span><br><span class="line">REPOSITORY TAG IMAGE ID CREATED SIZE</span><br><span class="line">hello-world latest d1165f221234 4 weeks ago 13.3kB</span><br></pre></td></tr></table></figure>

<p>了解：卸载docker</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 1.卸载依赖</span></span><br><span class="line">yum remove docker-ce docker-ce-cli containerd.io</span><br><span class="line"><span class="meta">#</span><span class="bash"> 2.删除资源</span></span><br><span class="line">rm -rf /var/lib/docker</span><br><span class="line">rm -rf /var/lib/containerd</span><br><span class="line"><span class="meta">#</span><span class="bash"> /var/lib/docker docker的默认⼯作路径</span></span><br></pre></td></tr></table></figure>

<h4 id="阿里云镜像加速"><a href="#阿里云镜像加速" class="headerlink" title="阿里云镜像加速"></a>阿里云镜像加速</h4><ol>
<li>登陆阿⾥云找到容器服务</li>
<li>找到镜像加速地址</li>
</ol>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/WKGTTP"><img src="https://z3.ax1x.com/2021/07/16/WKGTTP.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/16/WKGTTP.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="WKGTTP.png"></a></p>
<ol start="3">
<li>配置使⽤</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">sudo mkdir -p /etc/docker</span><br><span class="line">sudo tee /etc/docker/daemon.json &lt;&lt;-&#x27;EOF&#x27;</span><br><span class="line">&#123;</span><br><span class="line">  &quot;registry-mirrors&quot;: [&quot;https://s82h6lek.mirror.aliyuncs.com&quot;]</span><br><span class="line">&#125;</span><br><span class="line">EOF</span><br><span class="line">sudo systemctl daemon-reload</span><br><span class="line">sudo systemctl restart docker</span><br></pre></td></tr></table></figure>

<h4 id="华为云镜像加速"><a href="#华为云镜像加速" class="headerlink" title="华为云镜像加速"></a>华为云镜像加速</h4><p><a target="_blank" rel="noopener" href="https://blog.csdn.net/qq_43308275/article/details/112862370">Docker安装配置及华为云镜像加速_刘念的计算机空间-CSDN博客</a></p>
<h4 id="回顾helloworld"><a href="#回顾helloworld" class="headerlink" title="回顾helloworld"></a>回顾helloworld</h4><p>[<img src="https://z3.ax1x.com/2021/07/16/WKGhyd.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/16/WKGhyd.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="WKGhyd.png"></p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/WKJifU"><img src="https://z3.ax1x.com/2021/07/16/WKJifU.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/16/WKJifU.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="WKJifU.png"></a></p>
<h4 id="底层原理"><a href="#底层原理" class="headerlink" title="底层原理"></a>底层原理</h4><p><strong>Docker是怎么工作的？</strong></p>
<p>Docker是⼀个Client-Server结构的系统，Docker的守护进程运⾏在主机上，通过Socket从客户端访问！</p>
<p>Docker-server接收到Docker-Client的指令，就会执⾏！</p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/WKJE6J"><img src="https://z3.ax1x.com/2021/07/16/WKJE6J.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/16/WKJE6J.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="WKJE6J.png"></a></p>
<hr>
<p><strong>Docker为什么⽐vm快？</strong></p>
<ol>
<li><p>Docker有着⽐虚拟机更少的⽹络进程</p>
</li>
<li><p>Docker利⽤的是宿主机的内核，vm需要的是GuestOS；</p>
</li>
</ol>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/WKJVX9"><img src="https://z3.ax1x.com/2021/07/16/WKJVX9.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/16/WKJVX9.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="WKJVX9.png"></a></p>
<p>所以说，新建⼀个容器的时候，docker不需要像虚拟机⼀样重新加载⼀个操作系统内核，避免引导</p>
<p>型操作，虚拟机加载GuestOS，分钟级别的 ，Docker是利⽤宿主机的操作系统，省略了复杂的过</p>
<p>程，秒级！</p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/WKJm01"><img src="https://z3.ax1x.com/2021/07/16/WKJm01.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/16/WKJm01.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="WKJm01.png"></a></p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/WKJnTx"><img src="https://z3.ax1x.com/2021/07/16/WKJnTx.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/16/WKJnTx.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="WKJnTx.png"></a></p>
<h2 id="Docker常用命令"><a href="#Docker常用命令" class="headerlink" title="Docker常用命令"></a>Docker常用命令</h2><h4 id="帮助命令"><a href="#帮助命令" class="headerlink" title="帮助命令"></a>帮助命令</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">docker version # 显示docker的版本信息</span><br><span class="line">docker info # 显示docker的系统信息，包括镜像和容器的数量</span><br><span class="line">docker 命令 --help # 万能命令帮助</span><br></pre></td></tr></table></figure>

<p>帮助⽂档地址：<a target="_blank" rel="noopener" href="https://docs.docker.com/reference/">https://docs.docker.com/reference/</a></p>
<h4 id="镜像命令"><a href="#镜像命令" class="headerlink" title="镜像命令"></a>镜像命令</h4><p><strong>docker images 查看本地所有镜像</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost ~]# docker images</span><br><span class="line">REPOSITORY TAG IMAGE ID CREATED SIZE</span><br><span class="line">hello-world latest d1165f221234 4 weeks ago 13.3kB</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash">解释</span></span><br><span class="line">REPOSITORY 	镜像的仓库源</span><br><span class="line">TAG 		镜像的标签</span><br><span class="line">IMAGE ID 	镜像的ID</span><br><span class="line">CREATED 	镜像的创建时间</span><br><span class="line">SIZE 		镜像的⼤⼩</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash">可选项</span></span><br><span class="line">Options:</span><br><span class="line"> -a, --all 		#列出所有镜像</span><br><span class="line"> -q, --quiet 	#只显示镜像的ID</span><br></pre></td></tr></table></figure>

<hr>
<p><strong>docker search 搜索镜像</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">[root@192 roo]# docker search mysql</span><br><span class="line"></span><br><span class="line">NAME     DESCRIPTION      								STARS     OFFICIAL   AUTOMATED</span><br><span class="line">mysql    MySQL is a widely used, open-source relation…   11120     [OK]       </span><br><span class="line">mariadb  MariaDB Server is a high performing open sou…   4216      [OK]       </span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash">可选项，通过收藏过滤</span></span><br><span class="line">--filter=STARS=3000 #搜索出来的镜像就是STARS⼤于3000的</span><br><span class="line">[root@192 roo]# docker search mysql --filter=STARS=3000</span><br><span class="line">NAME      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED</span><br><span class="line">mysql     MySQL is a widely used, open-source relation…   11120     [OK]       </span><br><span class="line">mariadb   MariaDB Server is a high performing open sou…   4216      [OK]       </span><br><span class="line">[root@192 roo]# docker search mysql --filter=STARS=5000</span><br><span class="line">NAME      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED</span><br><span class="line">mysql     MySQL is a widely used, open-source relation…   11120     [OK]      </span><br></pre></td></tr></table></figure>

<hr>
<p><strong>docker pull 下载镜像</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">下载镜像 docker pull 镜像名[:tag版本]</span></span><br><span class="line">[root@localhost ~]# docker pull mysql</span><br><span class="line">Using default tag: latest #如果不写tag 默认就是latest</span><br><span class="line">latest: Pulling from library/mysql</span><br><span class="line">a076a628af6f: Pull complete #分层下载，docker image的核⼼ 联合⽂件系统</span><br><span class="line">f6c208f3f991: Pull complete </span><br><span class="line">88a9455a9165: Pull complete</span><br><span class="line">406c9b8427c6: Pull complete</span><br><span class="line">7c88599c0b25: Pull complete</span><br><span class="line">25b5c6debdaf: Pull complete</span><br><span class="line">43a5816f1617: Pull complete</span><br><span class="line">1a8c919e89bf: Pull complete</span><br><span class="line">9f3cf4bd1a07: Pull complete</span><br><span class="line">80539cea118d: Pull complete</span><br><span class="line">201b3cad54ce: Pull complete</span><br><span class="line">944ba37e1c06: Pull complete</span><br><span class="line">Digest: sha256:feada149cb8ff54eade1336da7c1d080c4a1c7ed82b5e320efb5beebed85ae8c</span><br><span class="line"><span class="meta">#</span><span class="bash">签名(防伪)</span></span><br><span class="line">Status: Downloaded newer image for mysql:latest</span><br><span class="line">docker.io/library/mysql:latest #真实地址</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash">等价</span></span><br><span class="line">docker pull mysql</span><br><span class="line">docker rmi 删除镜像！</span><br><span class="line">容器命令：</span><br><span class="line">说明：有了镜像才可以创建容器，linux，下载⼀个centos镜像来测试学习</span><br><span class="line">新建容器并启动</span><br><span class="line">docker pull docker.io/library/mysql:latest</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash">指定版本下载</span></span><br><span class="line">[root@localhost ~]# docker pull mysql:5.7</span><br><span class="line">5.7: Pulling from library/mysql</span><br><span class="line">a076a628af6f: Already exists</span><br><span class="line">f6c208f3f991: Already exists</span><br><span class="line">88a9455a9165: Already exists</span><br><span class="line">406c9b8427c6: Already exists</span><br><span class="line">7c88599c0b25: Already exists</span><br><span class="line">25b5c6debdaf: Already exists</span><br><span class="line">43a5816f1617: Already exists</span><br><span class="line">1831ac1245f4: Pull complete</span><br><span class="line">37677b8c1f79: Pull complete</span><br><span class="line">27e4ac3b0f6e: Pull complete</span><br><span class="line">7227baa8c445: Pull complete</span><br><span class="line">Digest: sha256:b3d1eff023f698cd433695c9506171f0d08a8f92a0c8063c1a4d9db9a55808df</span><br><span class="line">Status: Downloaded newer image for mysql:5.7</span><br><span class="line">docker.io/library/mysql:5.7</span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://www.z4a.net/image/g11IgJ"><img src="https://www.z4a.net/images/2021/07/16/image-20210714092609060.png" class="lazyload placeholder" data-srcset="https://www.z4a.net/images/2021/07/16/image-20210714092609060.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="image-20210714092609060.png"></a></p>
<p><strong>docker rmi 删除镜像！</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost ~]# docker rmi -f 镜像id #删除指定的镜像</span><br><span class="line">[root@localhost ~]# docker rmi -f 镜像id 镜像id 镜像id #删除多个镜像</span><br><span class="line">[root@localhost ~]# docker rmi -f $(docker images -aq) #删除全部的镜像</span><br></pre></td></tr></table></figure>



<h4 id="Docker容器命令"><a href="#Docker容器命令" class="headerlink" title="Docker容器命令"></a>Docker容器命令</h4><p><strong>说明：有了镜像才可以创建容器，linux，下载⼀个centos镜像来测试学习</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker pull centos</span><br></pre></td></tr></table></figure>

<p><strong>新建容器并启动</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">docker run [可选参数] images</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash">参数说明</span></span><br><span class="line">--name==&quot;Name&quot; 	容器名字 tomcat01 tomacat02，⽤来区分容器</span><br><span class="line">-d 				后台⽅式运⾏</span><br><span class="line">-it 			使⽤交互⽅式运⾏，进⼊容器查看内容</span><br><span class="line">-p 				指定容器的端⼝ -p 8080:8080</span><br><span class="line">				# -p ip:主机端⼝:容器端⼝ (常⽤) </span><br><span class="line">				# -p 主机端⼝:容器端⼝ (常⽤) </span><br><span class="line">				# -p 容器端⼝</span><br><span class="line">-P 				随机指定端⼝ </span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash">测试，启动并进⼊容器</span></span><br><span class="line">[root@localhost ~]# docker run -it centos /bin/bash</span><br><span class="line">[root@80138667de4f /]#</span><br><span class="line">[root@80138667de4f /]# ls #查看容器内的centos，基础版本，很多命令都是不完善的</span><br><span class="line">bin dev etc home lib lib64 lost+found media mnt opt proc root run </span><br><span class="line">sbin srv sys tmp usr var</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash">从容器中退回到主机</span></span><br><span class="line">[root@80138667de4f /]# exit</span><br><span class="line">exit</span><br><span class="line">[root@localhost ~]# ls</span><br><span class="line">anaconda-ks.cfg Desktop Documents Downloads initial-setup-ks.cfg Music </span><br><span class="line">Pictures Public Templates Videos</span><br></pre></td></tr></table></figure>

<hr>
<p><strong>列出当前正在运⾏的容器</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">docker ps 命令</span></span><br><span class="line"><span class="meta">		#</span><span class="bash">显示正在运⾏的容器</span></span><br><span class="line">-a 		# 列出当前正在运⾏的容器+带出历史运⾏过的容器</span><br><span class="line">-n=? 	#显示最近创作的容器</span><br><span class="line">-q 		# 只显示容器的编号</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash">docker ps -a</span></span><br><span class="line"><span class="meta">		#</span><span class="bash">显示曾经所有运行过的容器</span></span><br><span class="line"></span><br><span class="line">[root@192 roo]# docker ps</span><br><span class="line">CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES</span><br><span class="line">[root@192 roo]# docker ps -a</span><br><span class="line">CONTAINER ID   IMAGE         COMMAND       CREATED              STATUS                        PORTS     NAMES</span><br><span class="line">fce1a8d0bfaa   centos        &quot;/bin/bash&quot;   About a minute ago   Exited (127) 28 seconds ago             jolly_ritchie</span><br><span class="line">b81764395c1b   hello-world   &quot;/hello&quot;      6 minutes ago        Exited (0) 6 minutes ago                crazy_sanderson</span><br><span class="line">a2e6649d6749   hello-world   &quot;/hello&quot;      16 minutes ago       Exited (0) 16 minutes ago               wonderful_noether</span><br><span class="line">6db1aa868ed6   hello-world   &quot;/hello&quot;      15 hours ago         Exited (0) 15 hours ago                 loving_torvalds</span><br><span class="line">2a30c9d2e991   hello-world   &quot;/hello&quot;      38 hours ago         Exited (0) 38 hours ago                 hardcore_mahavira</span><br><span class="line">328fd8adb1e7   hello-world   &quot;/hello&quot;      38 hours ago         Exited (0) 38 hours ago                 practical_banzai</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<hr>
<p><strong>退出容器</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">exit 			#直接容器停⽌并退出</span><br><span class="line">ctrl + P + Q 	#容器不停⽌退出</span><br></pre></td></tr></table></figure>

<p><strong>删除容器</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">docker rm 容器id 							#删除指定的容器,不能删除正在运⾏的容器,如果要强制删除，rm -f</span><br><span class="line">docker rm -f $(docker ps -aq) 			#删除所有的容器</span><br><span class="line">docker ps -a -q| xargs docker rm 		#删除所有的容器</span><br></pre></td></tr></table></figure>

<p><strong>启动和停⽌容器的操作</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">docker start 容器id 		#启动容器</span><br><span class="line">docker restart 容器id 	#重启容器</span><br><span class="line">docker stop 容器id 		#停⽌当前正在运⾏的容器</span><br><span class="line">docker kill 容器id 		#强制停⽌当前容器</span><br></pre></td></tr></table></figure>

<h4 id="常⽤的其他命令"><a href="#常⽤的其他命令" class="headerlink" title="常⽤的其他命令:"></a>常⽤的其他命令:</h4><p><strong>后台启动容器</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 命令 docker run -d 镜像名</span></span><br><span class="line">[root@localhost ~]# docker run -d centos</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> docker ps 发现 centos停⽌了</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 常⻅的坑，docker容器使⽤后台运⾏就必须要有⼀个前台进程,docker发现没有应用，就会自动停止</span></span><br><span class="line"><span class="meta">#</span><span class="bash"> nginx，容器启动后，发现⾃⼰没有提供服务，就会⽴刻停⽌，就是没有程序了</span></span><br></pre></td></tr></table></figure>

<hr>
<p><strong>查看日志</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">docker logs --help</span><br><span class="line">docker logs -f -t -tail 容器id 	#没有⽇志</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> ⾃⼰编写⼀段shell脚本</span></span><br><span class="line">“while true; do echo LGQ ;sleep 2;done”</span><br><span class="line">[root@localhost ~]# docker run -d centos /bin/sh -c &quot;while true; do echo yangyang;sleep 1;done&quot;</span><br><span class="line">d303f1869bfb684c0d083ea61a56e00680b0787be5bcd2cb38af24c34f6c2ba2</span><br><span class="line">[root@localhost ~]# docker ps</span><br><span class="line">CONTAINER ID IMAGE COMMAND 					CREATED STATUS  PORTS 					NAMES</span><br><span class="line">d303f1869bfb centos &quot;/bin/sh -c &#x27;while t…&quot; 10 seconds ago 	Up 4 seconds	goofy_shannon</span><br><span class="line">2338d4c660bb centos &quot;/bin/bash&quot; 			12 minutes ago 	Up 12 minutes gifted_merkle</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 显示⽇志</span></span><br><span class="line">-tf				#显示日志</span><br><span class="line">--tail number 	#要显示的⽇志条数</span><br><span class="line">-n number 		#要显示的⽇志条数</span><br><span class="line">[root@localhost ~]# docker logs -tf --tail 10 d303f1869bfb</span><br></pre></td></tr></table></figure>

<hr>
<p><strong>查看容器中的进程信息</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 命令 docker top 容器id</span></span><br><span class="line">[root@192 roo]# docker top 0bb23343e3dc</span><br><span class="line">UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD</span><br><span class="line">root                7816                7797                1                   22:10               ?                   00:00:00            /bin/sh -c while true;do echo yangyang;sleep 1;done</span><br><span class="line">root                7905                7816                0                   22:10               ?                   00:00:00            /usr/bin/coreutils --coreutils-prog-shebang=sleep /usr/bin/sleep 1</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<hr>
<p><strong>查看镜像元数据</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 命令</span></span><br><span class="line">docker inspect 容器id</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 测试</span></span><br><span class="line">[root@192 roo]# docker inspect 0bb23343e3dc</span><br><span class="line">[</span><br><span class="line">    &#123;</span><br><span class="line">        &quot;Id&quot;: &quot;0bb23343e3dc15c70171cd97dca0abd3acea7327c0c3f1f6879a82c1234d5b7c&quot;,</span><br><span class="line">        &quot;Created&quot;: &quot;2021-07-14T02:10:07.055890513Z&quot;,</span><br><span class="line">        &quot;Path&quot;: &quot;/bin/sh&quot;,</span><br><span class="line">        &quot;Args&quot;: [</span><br><span class="line">            &quot;-c&quot;,</span><br><span class="line">            &quot;while true;do echo yangyang;sleep 1;done&quot;</span><br><span class="line">        ],</span><br><span class="line">        &quot;State&quot;: &#123;</span><br><span class="line">            &quot;Status&quot;: &quot;running&quot;,</span><br><span class="line">            &quot;Running&quot;: true,</span><br><span class="line">            &quot;Paused&quot;: false,</span><br><span class="line">            &quot;Restarting&quot;: false,</span><br><span class="line">            &quot;OOMKilled&quot;: false,</span><br><span class="line">            &quot;Dead&quot;: false,</span><br><span class="line">            &quot;Pid&quot;: 7816,</span><br><span class="line">            &quot;ExitCode&quot;: 0,</span><br><span class="line">            &quot;Error&quot;: &quot;&quot;,</span><br><span class="line">            &quot;StartedAt&quot;: &quot;2021-07-14T02:10:07.611405101Z&quot;,</span><br><span class="line">            &quot;FinishedAt&quot;: &quot;0001-01-01T00:00:00Z&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;Image&quot;: &quot;sha256:300e315adb2f96afe5f0b2780b87f28ae95231fe3bdd1e16b9ba606307728f55&quot;,</span><br><span class="line">        &quot;ResolvConfPath&quot;: &quot;/var/lib/docker/containers/0bb23343e3dc15c70171cd97dca0abd3acea7327c0c3f1f6879a82c1234d5b7c/resolv.conf&quot;,</span><br><span class="line">        &quot;HostnamePath&quot;: &quot;/var/lib/docker/containers/0bb23343e3dc15c70171cd97dca0abd3acea7327c0c3f1f6879a82c1234d5b7c/hostname&quot;,</span><br><span class="line">        &quot;HostsPath&quot;: &quot;/var/lib/docker/containers/0bb23343e3dc15c70171cd97dca0abd3acea7327c0c3f1f6879a82c1234d5b7c/hosts&quot;,</span><br><span class="line">        &quot;LogPath&quot;: &quot;/var/lib/docker/containers/0bb23343e3dc15c70171cd97dca0abd3acea7327c0c3f1f6879a82c1234d5b7c/0bb23343e3dc15c70171cd97dca0abd3acea7327c0c3f1f6879a82c1234d5b7c-json.log&quot;,</span><br><span class="line">        &quot;Name&quot;: &quot;/brave_boyd&quot;,</span><br><span class="line">        &quot;RestartCount&quot;: 0,</span><br><span class="line">        &quot;Driver&quot;: &quot;overlay2&quot;,</span><br><span class="line">        &quot;Platform&quot;: &quot;linux&quot;,</span><br><span class="line">        &quot;MountLabel&quot;: &quot;&quot;,</span><br><span class="line">        &quot;ProcessLabel&quot;: &quot;&quot;,</span><br><span class="line">        &quot;AppArmorProfile&quot;: &quot;&quot;,</span><br><span class="line">        &quot;ExecIDs&quot;: null,</span><br><span class="line">        &quot;HostConfig&quot;: &#123;</span><br><span class="line">            &quot;Binds&quot;: null,</span><br><span class="line">            &quot;ContainerIDFile&quot;: &quot;&quot;,</span><br><span class="line">            &quot;LogConfig&quot;: &#123;</span><br><span class="line">                &quot;Type&quot;: &quot;json-file&quot;,</span><br><span class="line">                &quot;Config&quot;: &#123;&#125;</span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;NetworkMode&quot;: &quot;default&quot;,</span><br><span class="line">            &quot;PortBindings&quot;: &#123;&#125;,</span><br><span class="line">            &quot;RestartPolicy&quot;: &#123;</span><br><span class="line">                &quot;Name&quot;: &quot;no&quot;,</span><br><span class="line">                &quot;MaximumRetryCount&quot;: 0</span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;AutoRemove&quot;: false,</span><br><span class="line">            &quot;VolumeDriver&quot;: &quot;&quot;,</span><br><span class="line">            &quot;VolumesFrom&quot;: null,</span><br><span class="line">            &quot;CapAdd&quot;: null,</span><br><span class="line">            &quot;CapDrop&quot;: null,</span><br><span class="line">            &quot;CgroupnsMode&quot;: &quot;host&quot;,</span><br><span class="line">            &quot;Dns&quot;: [],</span><br><span class="line">            &quot;DnsOptions&quot;: [],</span><br><span class="line">            &quot;DnsSearch&quot;: [],</span><br><span class="line">            &quot;ExtraHosts&quot;: null,</span><br><span class="line">            &quot;GroupAdd&quot;: null,</span><br><span class="line">            &quot;IpcMode&quot;: &quot;private&quot;,</span><br><span class="line">            &quot;Cgroup&quot;: &quot;&quot;,</span><br><span class="line">            &quot;Links&quot;: null,</span><br><span class="line">            &quot;OomScoreAdj&quot;: 0,</span><br><span class="line">            &quot;PidMode&quot;: &quot;&quot;,</span><br><span class="line">            &quot;Privileged&quot;: false,</span><br><span class="line">            &quot;PublishAllPorts&quot;: false,</span><br><span class="line">            &quot;ReadonlyRootfs&quot;: false,</span><br><span class="line">            &quot;SecurityOpt&quot;: null,</span><br><span class="line">            &quot;UTSMode&quot;: &quot;&quot;,</span><br><span class="line">            &quot;UsernsMode&quot;: &quot;&quot;,</span><br><span class="line">            &quot;ShmSize&quot;: 67108864,</span><br><span class="line">            &quot;Runtime&quot;: &quot;runc&quot;,</span><br><span class="line">            &quot;ConsoleSize&quot;: [</span><br><span class="line">                0,</span><br><span class="line">                0</span><br><span class="line">            ],</span><br><span class="line">            &quot;Isolation&quot;: &quot;&quot;,</span><br><span class="line">            &quot;CpuShares&quot;: 0,</span><br><span class="line">            &quot;Memory&quot;: 0,</span><br><span class="line">            &quot;NanoCpus&quot;: 0,</span><br><span class="line">            &quot;CgroupParent&quot;: &quot;&quot;,</span><br><span class="line">            &quot;BlkioWeight&quot;: 0,</span><br><span class="line">            &quot;BlkioWeightDevice&quot;: [],</span><br><span class="line">            &quot;BlkioDeviceReadBps&quot;: null,</span><br><span class="line">            &quot;BlkioDeviceWriteBps&quot;: null,</span><br><span class="line">            &quot;BlkioDeviceReadIOps&quot;: null,</span><br><span class="line">            &quot;BlkioDeviceWriteIOps&quot;: null,</span><br><span class="line">            &quot;CpuPeriod&quot;: 0,</span><br><span class="line">            &quot;CpuQuota&quot;: 0,</span><br><span class="line">            &quot;CpuRealtimePeriod&quot;: 0,</span><br><span class="line">            &quot;CpuRealtimeRuntime&quot;: 0,</span><br><span class="line">            &quot;CpusetCpus&quot;: &quot;&quot;,</span><br><span class="line">            &quot;CpusetMems&quot;: &quot;&quot;,</span><br><span class="line">            &quot;Devices&quot;: [],</span><br><span class="line">            &quot;DeviceCgroupRules&quot;: null,</span><br><span class="line">            &quot;DeviceRequests&quot;: null,</span><br><span class="line">            &quot;KernelMemory&quot;: 0,</span><br><span class="line">            &quot;KernelMemoryTCP&quot;: 0,</span><br><span class="line">            &quot;MemoryReservation&quot;: 0,</span><br><span class="line">            &quot;MemorySwap&quot;: 0,</span><br><span class="line">            &quot;MemorySwappiness&quot;: null,</span><br><span class="line">            &quot;OomKillDisable&quot;: false,</span><br><span class="line">            &quot;PidsLimit&quot;: null,</span><br><span class="line">            &quot;Ulimits&quot;: null,</span><br><span class="line">            &quot;CpuCount&quot;: 0,</span><br><span class="line">            &quot;CpuPercent&quot;: 0,</span><br><span class="line">            &quot;IOMaximumIOps&quot;: 0,</span><br><span class="line">            &quot;IOMaximumBandwidth&quot;: 0,</span><br><span class="line">            &quot;MaskedPaths&quot;: [</span><br><span class="line">                &quot;/proc/asound&quot;,</span><br><span class="line">                &quot;/proc/acpi&quot;,</span><br><span class="line">                &quot;/proc/kcore&quot;,</span><br><span class="line">                &quot;/proc/keys&quot;,</span><br><span class="line">                &quot;/proc/latency_stats&quot;,</span><br><span class="line">                &quot;/proc/timer_list&quot;,</span><br><span class="line">                &quot;/proc/timer_stats&quot;,</span><br><span class="line">                &quot;/proc/sched_debug&quot;,</span><br><span class="line">                &quot;/proc/scsi&quot;,</span><br><span class="line">                &quot;/sys/firmware&quot;</span><br><span class="line">            ],</span><br><span class="line">            &quot;ReadonlyPaths&quot;: [</span><br><span class="line">                &quot;/proc/bus&quot;,</span><br><span class="line">                &quot;/proc/fs&quot;,</span><br><span class="line">                &quot;/proc/irq&quot;,</span><br><span class="line">                &quot;/proc/sys&quot;,</span><br><span class="line">                &quot;/proc/sysrq-trigger&quot;</span><br><span class="line">            ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;GraphDriver&quot;: &#123;</span><br><span class="line">            &quot;Data&quot;: &#123;</span><br><span class="line">                &quot;LowerDir&quot;: &quot;/var/lib/docker/overlay2/31e3bc17c2d9a4927a25969af8159f2a978eac85b59da702f1b8b73dbd74c69b-init/diff:/var/lib/docker/overlay2/20b8e8381019a76417396ddc731cc09f767b78a17305e90e1ca2fab3eed8d937/diff&quot;,</span><br><span class="line">                &quot;MergedDir&quot;: &quot;/var/lib/docker/overlay2/31e3bc17c2d9a4927a25969af8159f2a978eac85b59da702f1b8b73dbd74c69b/merged&quot;,</span><br><span class="line">                &quot;UpperDir&quot;: &quot;/var/lib/docker/overlay2/31e3bc17c2d9a4927a25969af8159f2a978eac85b59da702f1b8b73dbd74c69b/diff&quot;,</span><br><span class="line">                &quot;WorkDir&quot;: &quot;/var/lib/docker/overlay2/31e3bc17c2d9a4927a25969af8159f2a978eac85b59da702f1b8b73dbd74c69b/work&quot;</span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;Name&quot;: &quot;overlay2&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;Mounts&quot;: [],</span><br><span class="line">        &quot;Config&quot;: &#123;</span><br><span class="line">            &quot;Hostname&quot;: &quot;0bb23343e3dc&quot;,</span><br><span class="line">            &quot;Domainname&quot;: &quot;&quot;,</span><br><span class="line">            &quot;User&quot;: &quot;&quot;,</span><br><span class="line">            &quot;AttachStdin&quot;: false,</span><br><span class="line">            &quot;AttachStdout&quot;: false,</span><br><span class="line">            &quot;AttachStderr&quot;: false,</span><br><span class="line">            &quot;Tty&quot;: false,</span><br><span class="line">            &quot;OpenStdin&quot;: false,</span><br><span class="line">            &quot;StdinOnce&quot;: false,</span><br><span class="line">            &quot;Env&quot;: [</span><br><span class="line">                &quot;PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin&quot;</span><br><span class="line">            ],</span><br><span class="line">            &quot;Cmd&quot;: [</span><br><span class="line">                &quot;/bin/sh&quot;,</span><br><span class="line">                &quot;-c&quot;,</span><br><span class="line">                &quot;while true;do echo yangyang;sleep 1;done&quot;</span><br><span class="line">            ],</span><br><span class="line">            &quot;Image&quot;: &quot;centos&quot;,</span><br><span class="line">            &quot;Volumes&quot;: null,</span><br><span class="line">            &quot;WorkingDir&quot;: &quot;&quot;,</span><br><span class="line">            &quot;Entrypoint&quot;: null,</span><br><span class="line">            &quot;OnBuild&quot;: null,</span><br><span class="line">            &quot;Labels&quot;: &#123;</span><br><span class="line">                &quot;org.label-schema.build-date&quot;: &quot;20201204&quot;,</span><br><span class="line">                &quot;org.label-schema.license&quot;: &quot;GPLv2&quot;,</span><br><span class="line">                &quot;org.label-schema.name&quot;: &quot;CentOS Base Image&quot;,</span><br><span class="line">                &quot;org.label-schema.schema-version&quot;: &quot;1.0&quot;,</span><br><span class="line">                &quot;org.label-schema.vendor&quot;: &quot;CentOS&quot;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;NetworkSettings&quot;: &#123;</span><br><span class="line">            &quot;Bridge&quot;: &quot;&quot;,</span><br><span class="line">            &quot;SandboxID&quot;: &quot;b14dbe27edc30bec32319d490380ec48c6a71763a2976535195fbfeb68b6b72b&quot;,</span><br><span class="line">            &quot;HairpinMode&quot;: false,</span><br><span class="line">            &quot;LinkLocalIPv6Address&quot;: &quot;&quot;,</span><br><span class="line">            &quot;LinkLocalIPv6PrefixLen&quot;: 0,</span><br><span class="line">            &quot;Ports&quot;: &#123;&#125;,</span><br><span class="line">            &quot;SandboxKey&quot;: &quot;/var/run/docker/netns/b14dbe27edc3&quot;,</span><br><span class="line">            &quot;SecondaryIPAddresses&quot;: null,</span><br><span class="line">            &quot;SecondaryIPv6Addresses&quot;: null,</span><br><span class="line">            &quot;EndpointID&quot;: &quot;b87ed48c0e8b119644d517e69061245e7d539bacba258c09106a4c8f9748b030&quot;,</span><br><span class="line">            &quot;Gateway&quot;: &quot;172.17.0.1&quot;,</span><br><span class="line">            &quot;GlobalIPv6Address&quot;: &quot;&quot;,</span><br><span class="line">            &quot;GlobalIPv6PrefixLen&quot;: 0,</span><br><span class="line">            &quot;IPAddress&quot;: &quot;172.17.0.2&quot;,</span><br><span class="line">            &quot;IPPrefixLen&quot;: 16,</span><br><span class="line">            &quot;IPv6Gateway&quot;: &quot;&quot;,</span><br><span class="line">            &quot;MacAddress&quot;: &quot;02:42:ac:11:00:02&quot;,</span><br><span class="line">            &quot;Networks&quot;: &#123;</span><br><span class="line">                &quot;bridge&quot;: &#123;</span><br><span class="line">                    &quot;IPAMConfig&quot;: null,</span><br><span class="line">                    &quot;Links&quot;: null,</span><br><span class="line">                    &quot;Aliases&quot;: null,</span><br><span class="line">                    &quot;NetworkID&quot;: &quot;099aaaefd6fd69860eb620959fb3786d3eed7271793a2400a742b02e14ff5e52&quot;,</span><br><span class="line">                    &quot;EndpointID&quot;: &quot;b87ed48c0e8b119644d517e69061245e7d539bacba258c09106a4c8f9748b030&quot;,</span><br><span class="line">                    &quot;Gateway&quot;: &quot;172.17.0.1&quot;,</span><br><span class="line">                    &quot;IPAddress&quot;: &quot;172.17.0.2&quot;,</span><br><span class="line">                    &quot;IPPrefixLen&quot;: 16,</span><br><span class="line">                    &quot;IPv6Gateway&quot;: &quot;&quot;,</span><br><span class="line">                    &quot;GlobalIPv6Address&quot;: &quot;&quot;,</span><br><span class="line">                    &quot;GlobalIPv6PrefixLen&quot;: 0,</span><br><span class="line">                    &quot;MacAddress&quot;: &quot;02:42:ac:11:00:02&quot;,</span><br><span class="line">                    &quot;DriverOpts&quot;: null</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">]</span><br></pre></td></tr></table></figure>

<hr>
<p><strong>进入当前正在运行的容器</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 我们通常容器id都是使⽤后台⽅式运⾏的，需要进⼊其中的容器，修改⼀些配置</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash">命令</span></span><br><span class="line">docker exec -it 容器id /bin/bash</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash">测试</span></span><br><span class="line">[root@192 roo]# docker ps</span><br><span class="line">CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS     NAMES</span><br><span class="line">0bb23343e3dc   centos    &quot;/bin/sh -c &#x27;while t…&quot;   5 minutes ago   Up 5 minutes             brave_boyd</span><br><span class="line">[root@192 roo]# docker exec -it 0bb23343e3dc /bin/bash</span><br><span class="line">[root@0bb23343e3dc /]# ls</span><br><span class="line">bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var</span><br><span class="line">[root@0bb23343e3dc /]# ps -ef</span><br><span class="line">UID          PID    PPID  C STIME TTY          TIME CMD</span><br><span class="line">root           1       0  0 02:10 ?        00:00:00 /bin/sh -c while true;do echo yangyang;sleep 1;done</span><br><span class="line">root         341       0  0 02:15 pts/0    00:00:00 /bin/bash</span><br><span class="line">root         493       1  0 02:17 ?        00:00:00 /usr/bin/coreutils --coreutils-prog-shebang=sleep /usr/bin/sleep 1</span><br><span class="line">root         494     341  0 02:17 pts/0    00:00:00 ps -ef</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 方式二</span></span><br><span class="line">docker attach 容器id</span><br><span class="line">正在执⾏当前的代码==&gt;</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash">docker <span class="built_in">exec</span> 		<span class="comment">#进⼊容器后开启⼀个新的终端，可以在里面操作（常用）</span></span></span><br><span class="line"><span class="meta">#</span><span class="bash">dockeer attach 	<span class="comment"># 进⼊容器正在执⾏的终端，不会执⾏新的进程！</span></span></span><br></pre></td></tr></table></figure>

<hr>
<p><strong>将容器内⽂件拷⻉到主机上</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line">docker cp 容器id:容器内路径 ⽬的主机路径</span><br><span class="line"><span class="meta">#</span><span class="bash">查看当前主机⽬录下</span></span><br><span class="line">[root@192 roo]# docker run -it centos /bin/bash</span><br><span class="line">[root@8636fcaea2e7 /]# [root@192 roo]# </span><br><span class="line">[root@192 roo]# docker ps</span><br><span class="line">CONTAINER ID   IMAGE     COMMAND       CREATED         STATUS         PORTS     NAMES</span><br><span class="line">8636fcaea2e7   centos    &quot;/bin/bash&quot;   9 seconds ago   Up 7 seconds             laughing_leavitt</span><br><span class="line">[root@192 roo]# cd  /home</span><br><span class="line">[root@192 home]# ls</span><br><span class="line">roo</span><br><span class="line">[root@192 home]# touch yangyang.java</span><br><span class="line">[root@192 home]# ls</span><br><span class="line">roo  yangyang.java</span><br><span class="line">[root@192 home]# docker ps</span><br><span class="line">CONTAINER ID   IMAGE     COMMAND       CREATED              STATUS          PORTS     NAMES</span><br><span class="line">8636fcaea2e7   centos    &quot;/bin/bash&quot;   About a minute ago   Up 59 seconds             laughing_leavitt</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash">进入容器内部</span></span><br><span class="line">[root@192 home]# docker attach 8636fcaea2e7 </span><br><span class="line">[root@8636fcaea2e7 /]# cd /home</span><br><span class="line">[root@8636fcaea2e7 home]# ls</span><br><span class="line">[root@8636fcaea2e7 home]# touch yangyang .java</span><br><span class="line">[root@8636fcaea2e7 home]# ls</span><br><span class="line">yangyang</span><br><span class="line">[root@8636fcaea2e7 home]# touch yangyang.java</span><br><span class="line">[root@8636fcaea2e7 home]# ls</span><br><span class="line">yangyang  yangyang.java</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash">将文件拷贝出来到主机上</span></span><br><span class="line">[root@8636fcaea2e7 home]# read escape sequence</span><br><span class="line">[root@192 home]# docker cp 8636fcaea2e7/home/yangyang /home</span><br><span class="line">must specify at least one container source</span><br><span class="line">[root@192 home]# docker cp 8636fcaea2e7:/home/yangyang /home</span><br><span class="line">[root@192 home]# ls</span><br><span class="line">roo  yangyang  yangyang.java</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 拷⻉是⼀个⼿动的过程 未来我们可以使⽤⼀个 -v 卷的技术，可以实现，⾃动同步</span></span><br></pre></td></tr></table></figure>

<p>==学习⽅式:将所有命令全部敲⼀遍，⾃⼰记录笔记！==</p>
<h4 id="小结"><a href="#小结" class="headerlink" title="小结"></a>小结</h4><img src="https://www.z4a.net/images/2021/07/16/image-20210714103003092.png" class="lazyload placeholder" data-srcset="https://www.z4a.net/images/2021/07/16/image-20210714103003092.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="image-20210714103003092.png" border="0" />

<hr>
<p><img src="https://www.z4a.net/images/2021/07/16/image-20210714103213163.png" class="lazyload placeholder" data-srcset="https://www.z4a.net/images/2021/07/16/image-20210714103213163.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="image-20210714103213163.png"></p>
<p><img src="https://www.z4a.net/images/2021/07/16/image-20210714103247654.png" class="lazyload placeholder" data-srcset="https://www.z4a.net/images/2021/07/16/image-20210714103247654.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="image-20210714103247654.png"></p>
<blockquote>
<p> docker的命令是⼗分多的，上⾯学习的搜是最常⽤的容器和镜像命令，之后还有很多命令</p>
<p>接下来就是练习</p>
</blockquote>
<h4 id="作业练习"><a href="#作业练习" class="headerlink" title="作业练习"></a>作业练习</h4><blockquote>
<p>Docker安装Nginx</p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 1.搜索镜像</span></span><br><span class="line"> docker search nginx</span><br><span class="line"><span class="meta">#</span><span class="bash"> 2.下载镜像</span></span><br><span class="line"> docker pull nginx</span><br><span class="line"><span class="meta">#</span><span class="bash"> 3.运行测试</span></span><br><span class="line">[root@192 ~]# docker images</span><br><span class="line">REPOSITORY    TAG       IMAGE ID       CREATED        SIZE</span><br><span class="line">nginx         latest    4cdc5dd7eaad   7 days ago     133MB</span><br><span class="line">hello-world   latest    d1165f221234   4 months ago   13.3kB</span><br><span class="line">centos        latest    300e315adb2f   7 months ago   209MB</span><br><span class="line"></span><br><span class="line">-d			# 后台运行</span><br><span class="line">--name		# 给容器命名</span><br><span class="line">-p			# 宿主机端口：容器内部端口</span><br><span class="line">[root@192 ~]# docker run -d --name nginx01 -p 3344:80 nginx</span><br><span class="line">7c882abe2415bd35124e5026782c72df61806c41a039e844a19ec92a17bd3066</span><br><span class="line">[root@192 ~]# docker ps</span><br><span class="line">CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                                   NAMES</span><br><span class="line">7c882abe2415   nginx     &quot;/docker-entrypoint.…&quot;   3 seconds ago   Up 2 seconds   0.0.0.0:3344-&gt;80/tcp, :::3344-&gt;80/tcp   nginx01</span><br><span class="line">[root@192 ~]# curl 127.0.0.1:3344</span><br><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">&lt;title&gt;Welcome to nginx!&lt;/title&gt;</span><br><span class="line">&lt;style&gt;</span><br><span class="line">    body &#123;</span><br><span class="line">        width: 35em;</span><br><span class="line">        margin: 0 auto;</span><br><span class="line">        font-family: Tahoma, Verdana, Arial, sans-serif;</span><br><span class="line">    &#125;</span><br><span class="line">&lt;/style&gt;</span><br><span class="line">&lt;/head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line">&lt;h1&gt;Welcome to nginx!&lt;/h1&gt;</span><br><span class="line">&lt;p&gt;If you see this page, the nginx web server is successfully installed and</span><br><span class="line">working. Further configuration is required.&lt;/p&gt;</span><br><span class="line"></span><br><span class="line">&lt;p&gt;For online documentation and support please refer to</span><br><span class="line">&lt;a href=&quot;http://nginx.org/&quot;&gt;nginx.org&lt;/a&gt;.&lt;br/&gt;</span><br><span class="line">Commercial support is available at</span><br><span class="line">&lt;a href=&quot;http://nginx.com/&quot;&gt;nginx.com&lt;/a&gt;.&lt;/p&gt;</span><br><span class="line"></span><br><span class="line">&lt;p&gt;&lt;em&gt;Thank you for using nginx.&lt;/em&gt;&lt;/p&gt;</span><br><span class="line">&lt;/body&gt;</span><br><span class="line">&lt;/html&gt;</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash">进入容器</span></span><br><span class="line">[root@192 ~]# docker exec -it nginx01 /bin/bash</span><br><span class="line">root@7c882abe2415:/# whereis nginx</span><br><span class="line">nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx</span><br><span class="line">root@7c882abe2415:/# cd /etc/nginx</span><br><span class="line">root@7c882abe2415:/etc/nginx# ls</span><br><span class="line">conf.d	fastcgi_params	mime.types  modules  nginx.conf  scgi_params  uwsgi_params</span><br><span class="line">root@7c882abe2415:/etc/nginx# </span><br><span class="line"></span><br></pre></td></tr></table></figure>

<img src="https://www.z4a.net/images/2021/07/17/image-20210714110359456.png" class="lazyload placeholder" data-srcset="https://www.z4a.net/images/2021/07/17/image-20210714110359456.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="image-20210714110359456.png" border="0" />

<p>思考问题：我们每次改动nginx配置文件，都需要进入容器内部?十分的麻烦，我要是可以在容器外部提供一个映射路径，达到在容器修改文件名，容器内部就可以自动修改?    -v    数据卷?</p>
<blockquote>
<p>Docker来安装⼀个tomcat</p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 官⽅的使⽤</span></span><br><span class="line">docker run -it --rm tomcat:9.0</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 我们之前的启动都是后台，停⽌了容器之后，容器还可以查到 docker run -it --rm 	⼀般⽤来测试，⽤完即删</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 先下载再启动</span></span><br><span class="line">docker pull tomcat:9.0</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 启动并运⾏</span></span><br><span class="line">[root@192 ~]# docker run -d -p 3355:8080 --name tomcat01 tomcat</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash">  测试访问没有问题</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 进入容器</span></span><br><span class="line">[root@192 ~]# docker exec -it tomcat01 /bin/bash</span><br><span class="line"><span class="meta">#</span><span class="bash"> 发现问题：1、linux命令少了2、没有webapps。阿里云镜像的原因，默认是最小的镜像，所以不必要的都剔除了</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash">部署tomcat</span></span><br><span class="line">[root@192 ~]# docker exec -it tomcat01 /bin/bash</span><br><span class="line">root@c73003bfe775:/usr/local/tomcat# ls</span><br><span class="line">BUILDING.txt	 LICENSE  README.md	 RUNNING.txt  conf  logs	    temp     webapps.dist</span><br><span class="line">CONTRIBUTING.md  NOTICE   RELEASE-NOTES  bin	      lib   native-jni-lib  webapps  work</span><br><span class="line">root@c73003bfe775:/usr/local/tomcat# ll</span><br><span class="line">bash: ll: command not found</span><br><span class="line">root@c73003bfe775:/usr/local/tomcat# cd webapps.dist</span><br><span class="line">root@c73003bfe775:/usr/local/tomcat/webapps.dist# ls</span><br><span class="line">ROOT  docs  examples  host-manager  manager</span><br><span class="line">root@c73003bfe775:/usr/local/tomcat/webapps.dist# cd ../</span><br><span class="line">root@c73003bfe775:/usr/local/tomcat# cp -r webapps.dist/* webapps</span><br><span class="line">root@c73003bfe775:/usr/local/tomcat# cd webapps</span><br><span class="line">root@c73003bfe775:/usr/local/tomcat/webapps# ls</span><br><span class="line">ROOT  docs  examples  host-manager  manager</span><br><span class="line"><span class="meta">#</span><span class="bash">访问外网，没有问题</span></span><br></pre></td></tr></table></figure>

<p>思考问题：我们以后要部署项目，如果每次都要进入容器是不是十分麻烦？我要是可以在容器外部提供一个映射路径 , webapps，我们在外部放置项目，就自动同步到内部就好了!</p>
<blockquote>
<p>部署es+kibana</p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> es 暴露的端⼝很多</span></span><br><span class="line"><span class="meta">#</span><span class="bash"> es ⼗分消耗内存</span></span><br><span class="line"><span class="meta">#</span><span class="bash"> es 的数据⼀般需要放置到安全⽬录！挂载</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash">启动 elasticsearch</span></span><br><span class="line">思考：使⽤kibana连接es？思考如何才能连接过去</span><br><span class="line">可视化</span><br><span class="line">docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e &quot;discovery.type=single-node&quot; elasticsearch:7.6.2</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 启动了，linux就卡住了 docker stats查看cpu的状态</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 测试es是否成功</span></span><br><span class="line">[root@192 ~]# curl 127.0.0.1:9200</span><br><span class="line">&#123;</span><br><span class="line">  &quot;name&quot; : &quot;2464c92a9984&quot;,</span><br><span class="line">  &quot;cluster_name&quot; : &quot;docker-cluster&quot;,</span><br><span class="line">  &quot;cluster_uuid&quot; : &quot;8srwqr_wR2acAIY6WvIwFg&quot;,</span><br><span class="line">  &quot;version&quot; : &#123;</span><br><span class="line">    &quot;number&quot; : &quot;7.6.2&quot;,</span><br><span class="line">    &quot;build_flavor&quot; : &quot;default&quot;,</span><br><span class="line">    &quot;build_type&quot; : &quot;docker&quot;,</span><br><span class="line">    &quot;build_hash&quot; : &quot;ef48eb35cf30adf4db14086e8aabd07ef6fb113f&quot;,</span><br><span class="line">    &quot;build_date&quot; : &quot;2020-03-26T06:34:37.794943Z&quot;,</span><br><span class="line">    &quot;build_snapshot&quot; : false,</span><br><span class="line">    &quot;lucene_version&quot; : &quot;8.4.0&quot;,</span><br><span class="line">    &quot;minimum_wire_compatibility_version&quot; : &quot;6.8.0&quot;,</span><br><span class="line">    &quot;minimum_index_compatibility_version&quot; : &quot;6.0.0-beta1&quot;</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;tagline&quot; : &quot;You Know, for Search&quot;</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> es 是⼗分耗内存的</span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 查看 docker stats</span></span><br><span class="line"><span class="meta">#</span><span class="bash">赶紧关闭，增加内存限制</span></span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1Cgf0"><img src="https://z3.ax1x.com/2021/07/17/W1Cgf0.md.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1Cgf0.md.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1Cgf0.md.png"></a></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">赶紧关闭，增加内存限制,修改配置⽂件 -e 环境配置修改</span></span><br><span class="line">[root@192 ~]# docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e &quot;discovery.type=single-node&quot; -e ES_JAVA_OPTS=&quot;-Xms64m -Xmx512m&quot; elasticsearch:7.6.2</span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1CRpV"><img src="https://z3.ax1x.com/2021/07/17/W1CRpV.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1CRpV.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1CRpV.png"></a></p>
<p>思考：使⽤kibana连接es？思考如何才能连接过去!</p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1PPht"><img src="https://z3.ax1x.com/2021/07/17/W1PPht.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1PPht.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1PPht.png"></a></p>
<h4 id="可视化"><a href="#可视化" class="headerlink" title="可视化"></a>可视化</h4><ul>
<li>portainer(先⽤这个)</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker run -d -p 8088:9000 \</span><br><span class="line">--restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer</span><br></pre></td></tr></table></figure>

<ul>
<li>Rancher(CI/CD再⽤)</li>
</ul>
<p><strong>什么是portainer?</strong></p>
<p>Docker 图形化界⾯管理⼯具！提供⼀个后台⾯板供我们操作</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker run -d -p 8088:9000 \</span><br><span class="line">--restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer</span><br></pre></td></tr></table></figure>

<p>访问测试：外⽹：8088 <a target="_blank" rel="noopener" href="http://192.168.80.1:8088/#/init/admin">http://192.168.80.1:8088/#/init/admin</a></p>
<p>通过它来访问</p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1P09x"><img src="https://z3.ax1x.com/2021/07/17/W1P09x.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1P09x.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1P09x.png"></a></p>
<p>选择本地的</p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1PrjO"><img src="https://z3.ax1x.com/2021/07/17/W1PrjO.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1PrjO.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1PrjO.png"></a></p>
<p>进入之后的面板</p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1P6De"><img src="https://z3.ax1x.com/2021/07/17/W1P6De.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1P6De.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1P6De.png"></a></p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1PhCt"><img src="https://z3.ax1x.com/2021/07/17/W1PhCt.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1PhCt.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1PhCt.png"></a></p>
<p>可视化⾯板平时不会⽤，测试完即可</p>
<h2 id="Docker镜像讲解"><a href="#Docker镜像讲解" class="headerlink" title="Docker镜像讲解"></a>Docker镜像讲解</h2><h4 id="镜像是什么"><a href="#镜像是什么" class="headerlink" title="镜像是什么"></a>镜像是什么</h4><p>镜像是⼀种轻量级可执⾏的软件包，⽤来打包软件的运⾏环境和基于环境开发的软件，包含运⾏某个软件所需要的所有内容，包括代码，运⾏时库，环境变量和配置⽂件</p>
<p>所有的应⽤直接打包docker镜像，就可以直接运⾏</p>
<p>如何得到镜像：</p>
<ul>
<li>从远程仓库下载</li>
<li>朋友拷⻉</li>
<li>自己制作⼀个镜像 DockerFile</li>
</ul>
<h4 id="Docker镜像加速"><a href="#Docker镜像加速" class="headerlink" title="Docker镜像加速"></a>Docker镜像加速</h4><blockquote>
<p>UnionFS(联合⽂件系统)</p>
</blockquote>
<p>我们下载的时候看到的⼀层⼀层就是这个<a target="_blank" rel="noopener" href="https://imgtu.com/i/W1PTKS"><img src="https://z3.ax1x.com/2021/07/17/W1PTKS.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1PTKS.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1PTKS.png"></a></p>
<p>UnionFS(联合⽂件系统)：Union⽂件系统(UnionFS)是⼀种分层轻量级并且⾼性能的⽂件系统，他⽀持对⽂件系统的更改，作为⼀次提交来⼀层层的叠加，同时可以将不同的⽬录挂载到同⼀个虚拟⽂件系统下（unite several directories into a single virtual filesystem）。Union⽂件系统是Docker镜像的基础，镜像可以通过分层来继承，基于基础镜像（没有⽗镜像），可以制作各种具体的镜像。</p>
<p>特性：⼀次同时加载多个⽂件系统，但从外⾯来看，只能看到⼀个⽂件系统联合加载会把各层⽂件系统叠加起来，这样最终⽂件系统会包括所有底层的⽂件和⽬录</p>
<p>知乎解读：<a target="_blank" rel="noopener" href="https://zhuanlan.zhihu.com/p/47025759?from_voters_page=true">https://zhuanlan.zhihu.com/p/47025759?from_voters_page=true</a></p>
<hr>
<blockquote>
<p>Docker镜像加载的原理</p>
</blockquote>
<p>Docker镜像实际由⼀层层的⽂件系统组成，这种层级的⽂件系统UnionFS。</p>
<p>bootfs(coot dile system)主要包含bootloader和kernel，bootloader主要是引导加载kernel，Linux刚启动时会加载bootfs的⽂件系统，在docker镜像的最底层时是botfs。这⼀层与我们典型的Linux/Unix是⼀样的，包含boot加载器和内核，当boot加载完之后整个内核就在内存中了，此时的内存使⽤权已由bootfs转交给内核，此时系统也会卸载bootfs。</p>
<p>⿊屏—开机进⼊系统</p>
<p>rootfs(root file system)，在bootfs上，包含的就是典型的Linux系统中的/dev，/proc，/bin，/etc等标准⽬录⽂件，rootfs就是各种不同的操作系统的发⾏版，⽐如ubuntu，Centos等等；</p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1PHbQ"><img src="https://z3.ax1x.com/2021/07/17/W1PHbQ.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1PHbQ.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1PHbQ.png"></a></p>
<p>平时我们安装的虚拟机的CentOS都是好⼏个G，为什么Docker这⾥才200M？</p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1PO5n"><img src="https://z3.ax1x.com/2021/07/17/W1PO5n.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1PO5n.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1PO5n.png"></a></p>
<p>对于⼀个精简的OS，rootfs可以⼩，只需要包含最基本的命令，⼯具和程序库就可以了，因为底层直接⽤host的kernel，⾃⼰只需要提供⼀个rootfs酷可以了，由此可⻅对于不同的linux发⾏版bootfs‘基本上是⼀致的，rootfs‘会有差别，因此不同的发⾏版可以公⽤bootfs。</p>
<p><strong>虚拟机是分钟级别的，容器是秒级的</strong></p>
<h4 id="分层理解"><a href="#分层理解" class="headerlink" title="分层理解"></a>分层理解</h4><blockquote>
<p>分层的镜像</p>
</blockquote>
<p>我们可以下载⼀个镜像，注意观察下载的⽇志输出，可以看到是⼀层⼀层在下载！</p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1iBIs"><img src="https://z3.ax1x.com/2021/07/17/W1iBIs.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1iBIs.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1iBIs.png"></a></p>
<p>思考：为什么docker镜像要采⽤这种分层结构呢？</p>
<p>最⼤的好处就是资源共享，⽐如有多个镜像都从想通的base镜像构建⽽来，那么宿主机只需在磁盘上保留⼀份base镜像，同时内存中也只需要加载⼀份镜像，这样就可以为所有的容器服务了，⽽且镜像的每⼀层都可以共享。</p>
<p>查看镜像分层的⽅式可以通过<code>docker image inspect</code> 命令！</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br></pre></td><td class="code"><pre><span class="line">[root@192 ~]# docker pull redis</span><br><span class="line">Using default tag: latest</span><br><span class="line">latest: Pulling from library/redis</span><br><span class="line">b4d181a07f80: Already exists </span><br><span class="line">86e428f79bcb: Pull complete </span><br><span class="line">ba0d0a025810: Pull complete </span><br><span class="line">ba9292c6f77e: Pull complete </span><br><span class="line">b96c0d1da602: Pull complete </span><br><span class="line">5e4b46455da3: Pull complete </span><br><span class="line">Digest: sha256:b6a9fc3535388a6fc04f3bdb83fb4d9d0b4ffd85e7609a6ff2f0f731427823e3</span><br><span class="line">Status: Downloaded newer image for redis:latest</span><br><span class="line">docker.io/library/redis:latest</span><br><span class="line">[root@192 ~]# docker image inspect redis:latest</span><br><span class="line">[</span><br><span class="line">    &#123;</span><br><span class="line">        &quot;Id&quot;: &quot;sha256:08502081bff61084d64fc76f0f90ea39b89935cd071d9e12c5374ae191ff53c0&quot;,</span><br><span class="line">        &quot;RepoTags&quot;: [</span><br><span class="line">            &quot;redis:latest&quot;</span><br><span class="line">        ],</span><br><span class="line">        &quot;RepoDigests&quot;: [</span><br><span class="line">            &quot;redis@sha256:b6a9fc3535388a6fc04f3bdb83fb4d9d0b4ffd85e7609a6ff2f0f731427823e3&quot;</span><br><span class="line">        ],</span><br><span class="line">        &quot;Parent&quot;: &quot;&quot;,</span><br><span class="line">        &quot;Comment&quot;: &quot;&quot;,</span><br><span class="line">        &quot;Created&quot;: &quot;2021-06-23T16:36:30.182210591Z&quot;,</span><br><span class="line">        &quot;Container&quot;: &quot;ff24eb24b3cff07ced352081b984ecafb749404469993462cbd773258d1a56fe&quot;,</span><br><span class="line">        &quot;ContainerConfig&quot;: &#123;</span><br><span class="line">            &quot;Hostname&quot;: &quot;ff24eb24b3cf&quot;,</span><br><span class="line">            &quot;Domainname&quot;: &quot;&quot;,</span><br><span class="line">            &quot;User&quot;: &quot;&quot;,</span><br><span class="line">            &quot;AttachStdin&quot;: false,</span><br><span class="line">            &quot;AttachStdout&quot;: false,</span><br><span class="line">            &quot;AttachStderr&quot;: false,</span><br><span class="line">            &quot;ExposedPorts&quot;: &#123;</span><br><span class="line">                &quot;6379/tcp&quot;: &#123;&#125;</span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;Tty&quot;: false,</span><br><span class="line">            &quot;OpenStdin&quot;: false,</span><br><span class="line">            &quot;StdinOnce&quot;: false,</span><br><span class="line">            &quot;Env&quot;: [</span><br><span class="line">                &quot;PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin&quot;,</span><br><span class="line">                &quot;GOSU_VERSION=1.12&quot;,</span><br><span class="line">                &quot;REDIS_VERSION=6.2.4&quot;,</span><br><span class="line">                &quot;REDIS_DOWNLOAD_URL=http://download.redis.io/releases/redis-6.2.4.tar.gz&quot;,</span><br><span class="line">                &quot;REDIS_DOWNLOAD_SHA=ba32c406a10fc2c09426e2be2787d74ff204eb3a2e496d87cff76a476b6ae16e&quot;</span><br><span class="line">            ],</span><br><span class="line">            &quot;Cmd&quot;: [</span><br><span class="line">                &quot;/bin/sh&quot;,</span><br><span class="line">                &quot;-c&quot;,</span><br><span class="line">                &quot;#(nop) &quot;,</span><br><span class="line">                &quot;CMD [\&quot;redis-server\&quot;]&quot;</span><br><span class="line">            ],</span><br><span class="line">            &quot;Image&quot;: &quot;sha256:e39f8a5eb6f06bc15438105f98a52afaa51dc6fb498e2e49ddc5e38916478394&quot;,</span><br><span class="line">            &quot;Volumes&quot;: &#123;</span><br><span class="line">                &quot;/data&quot;: &#123;&#125;</span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;WorkingDir&quot;: &quot;/data&quot;,</span><br><span class="line">            &quot;Entrypoint&quot;: [</span><br><span class="line">                &quot;docker-entrypoint.sh&quot;</span><br><span class="line">            ],</span><br><span class="line">            &quot;OnBuild&quot;: null,</span><br><span class="line">            &quot;Labels&quot;: &#123;&#125;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;DockerVersion&quot;: &quot;19.03.12&quot;,</span><br><span class="line">        &quot;Author&quot;: &quot;&quot;,</span><br><span class="line">        &quot;Config&quot;: &#123;</span><br><span class="line">            &quot;Hostname&quot;: &quot;&quot;,</span><br><span class="line">            &quot;Domainname&quot;: &quot;&quot;,</span><br><span class="line">            &quot;User&quot;: &quot;&quot;,</span><br><span class="line">            &quot;AttachStdin&quot;: false,</span><br><span class="line">            &quot;AttachStdout&quot;: false,</span><br><span class="line">            &quot;AttachStderr&quot;: false,</span><br><span class="line">            &quot;ExposedPorts&quot;: &#123;</span><br><span class="line">                &quot;6379/tcp&quot;: &#123;&#125;</span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;Tty&quot;: false,</span><br><span class="line">            &quot;OpenStdin&quot;: false,</span><br><span class="line">            &quot;StdinOnce&quot;: false,</span><br><span class="line">            &quot;Env&quot;: [</span><br><span class="line">                &quot;PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin&quot;,</span><br><span class="line">                &quot;GOSU_VERSION=1.12&quot;,</span><br><span class="line">                &quot;REDIS_VERSION=6.2.4&quot;,</span><br><span class="line">                &quot;REDIS_DOWNLOAD_URL=http://download.redis.io/releases/redis-6.2.4.tar.gz&quot;,</span><br><span class="line">                &quot;REDIS_DOWNLOAD_SHA=ba32c406a10fc2c09426e2be2787d74ff204eb3a2e496d87cff76a476b6ae16e&quot;</span><br><span class="line">            ],</span><br><span class="line">            &quot;Cmd&quot;: [</span><br><span class="line">                &quot;redis-server&quot;</span><br><span class="line">            ],</span><br><span class="line">            &quot;Image&quot;: &quot;sha256:e39f8a5eb6f06bc15438105f98a52afaa51dc6fb498e2e49ddc5e38916478394&quot;,</span><br><span class="line">            &quot;Volumes&quot;: &#123;</span><br><span class="line">                &quot;/data&quot;: &#123;&#125;</span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;WorkingDir&quot;: &quot;/data&quot;,</span><br><span class="line">            &quot;Entrypoint&quot;: [</span><br><span class="line">                &quot;docker-entrypoint.sh&quot;</span><br><span class="line">            ],</span><br><span class="line">            &quot;OnBuild&quot;: null,</span><br><span class="line">            &quot;Labels&quot;: null</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;Architecture&quot;: &quot;amd64&quot;,</span><br><span class="line">        &quot;Os&quot;: &quot;linux&quot;,</span><br><span class="line">        &quot;Size&quot;: 105394545,</span><br><span class="line">        &quot;VirtualSize&quot;: 105394545,</span><br><span class="line">        &quot;GraphDriver&quot;: &#123;</span><br><span class="line">            &quot;Data&quot;: &#123;</span><br><span class="line">                &quot;LowerDir&quot;: &quot;/var/lib/docker/overlay2/2d481fb67b4236c0de192288f3dc2b1052fc5326e24f15f208390b2f6424b948/diff:/var/lib/docker/overlay2/901e9c9ea320b633f37bc0a7268e8a46bc7083d7dd7a6453d1614455d5d1fbe5/diff:/var/lib/docker/overlay2/028089062f384a27789ab22779d1a9ae90e1f603efedd2abb27509a5b5811267/diff:/var/lib/docker/overlay2/f418e7b2f54a421ffd1583543fc8cc2fcdf94ad3805f096adcb7bf6e2e93e19b/diff:/var/lib/docker/overlay2/7544f583bcb8cb845806da98a5f92187843e0effb03497750b684052f410f46f/diff&quot;,</span><br><span class="line">                &quot;MergedDir&quot;: &quot;/var/lib/docker/overlay2/186f7933146e3cac0b58373d7e10b6b667f99e4f3c17fb150feeccd741151733/merged&quot;,</span><br><span class="line">                &quot;UpperDir&quot;: &quot;/var/lib/docker/overlay2/186f7933146e3cac0b58373d7e10b6b667f99e4f3c17fb150feeccd741151733/diff&quot;,</span><br><span class="line">                &quot;WorkDir&quot;: &quot;/var/lib/docker/overlay2/186f7933146e3cac0b58373d7e10b6b667f99e4f3c17fb150feeccd741151733/work&quot;</span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;Name&quot;: &quot;overlay2&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;RootFS&quot;: &#123;</span><br><span class="line">            &quot;Type&quot;: &quot;layers&quot;,</span><br><span class="line">            &quot;Layers&quot;: [</span><br><span class="line">                &quot;sha256:764055ebc9a7a290b64d17cf9ea550f1099c202d83795aa967428ebdf335c9f7&quot;,</span><br><span class="line">                &quot;sha256:245c9d23f65373415922e53424032cabe7b282c5cf8f9f8070a7d1830fca6871&quot;,</span><br><span class="line">                &quot;sha256:ebef6caacb966ed54c0c3facf2288fa5124452f2c0a17faa1941625eab0ceb54&quot;,</span><br><span class="line">                &quot;sha256:0b7b774038f08ec329e4dd2c0be440c487cfb003a05fce87cd5d1497b602f2c1&quot;,</span><br><span class="line">                &quot;sha256:a71d36a87572d637aa446110faf8abb4ea74f028d0e0737f2ff2b983ef23abf3&quot;,</span><br><span class="line">                &quot;sha256:9e1fddfb3a22146392a2d6491e1af2f087da5e6551849a6174fa23051ef8a38f&quot;</span><br><span class="line">            ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;Metadata&quot;: &#123;</span><br><span class="line">            &quot;LastTagTime&quot;: &quot;0001-01-01T00:00:00Z&quot;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">]</span><br></pre></td></tr></table></figure>

<p>理解：</p>
<p>所有的docker镜像都起源于⼀个基础镜像层，当进⾏修改或增加新的内容时，就会在当前的镜像层上，创建新的镜像层。</p>
<p>举⼀个简单的例⼦，假如基于Ubuntu linux 16.04创建⼀个新的镜像，这就是镜像的第⼀层；如果在该镜像中添加python包，就会在基础镜像上创建第⼆个镜像层；如果继续添加⼀个安全补丁，就会创建第三个镜像层。</p>
<p>改镜像当前已经包含3个镜像层如下图所示<a target="_blank" rel="noopener" href="https://imgtu.com/i/W1ihdJ"><img src="https://z3.ax1x.com/2021/07/17/W1ihdJ.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1ihdJ.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1ihdJ.png"></a></p>
<p>在添加额外镜像层的同时，镜像始终保持着当前所有镜像的组合，理解着⼀点⾮常重要，下图举了⼀个⾮常简单的例⼦，每个镜像层包含3个⽂件，⽽镜像包含了来⾃两个镜像层的6个⽂件<a target="_blank" rel="noopener" href="https://imgtu.com/i/W1iLLD"><img src="https://z3.ax1x.com/2021/07/17/W1iLLD.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1iLLD.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1iLLD.png"></a></p>
<p>上⾯的镜像层和之前的略有区别，主要⽬的是便于展示⽂件。</p>
<p>下图站是了⼀个稍微复杂的三层镜像，在外部看来整个镜像只有6个⽂件，这是因为最上层的⽂件7是⽂件5的更新版<a target="_blank" rel="noopener" href="https://imgtu.com/i/W1izFA"><img src="https://z3.ax1x.com/2021/07/17/W1izFA.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1izFA.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1izFA.png"></a></p>
<p>这种情况下，上层镜像的⽂件覆盖了底层镜像的⽂件，这样就使得⽂件的更新版本作为⼀个镜像层添加</p>
<p>到镜像中。</p>
<p>Docker通过存储引擎（新版本采⽤快照机制）的⽅式来实现镜像层的堆栈，并保证多镜像层对外展示为统⼀的⽂件系统。</p>
<p>Linux上可⽤的存储引擎有AUFS，Overlay2，Decvice Mapper，Btrfs以及ZFS。顾名思义，每种存储引擎都基于LInux中对应的⽂件系统或者快设备技术，并且每种存储引擎都有独有的性能特点。</p>
<p>Docker在winows仅⽀持windowsfilter⼀种存储引擎，改引擎基于NTFS⽂件系统之上实现了分层和cow[1]。</p>
<p>下⾯展示了与系统显示相同的三层镜像，所有镜像层堆叠并合并，对外提供统⼀的视图。</p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1FsTH"><img src="https://z3.ax1x.com/2021/07/17/W1FsTH.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1FsTH.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1FsTH.png"></a></p>
<hr>
<blockquote>
<p>特点</p>
</blockquote>
<p>Docker镜像都是只读的，当容器启动时，⼀个新的可写层被加载到镜像的顶部！</p>
<p>这⼀层就是我们通常说的容器层，容器层之下就是镜像层！</p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1FctA"><img src="https://z3.ax1x.com/2021/07/17/W1FctA.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1FctA.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1FctA.png"></a></p>
<p>如何提交⼀个⾃⼰的镜像？</p>
<h4 id="commit镜像"><a href="#commit镜像" class="headerlink" title="commit镜像"></a>commit镜像</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">docker commit 提交容器成为⼀个新的副本</span><br><span class="line"><span class="meta">#</span><span class="bash">命令和git类似</span></span><br><span class="line">docker commit -m=&quot;提交的描述信息&quot; -a=&quot;作者&quot; 容器id ⽬标镜像名:[TAG]</span><br></pre></td></tr></table></figure>

<p>实战测试：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 1.启动⼀个默认的tomacat</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 2.发现这个默认的tomcat是没有webapps的，镜像的原因，官⽅的镜像默认的webapps下⾯是没有⽂件的</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 3.我⾃⼰拷⻉进去了⼀个基本⽂件</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 4.将我们操作过的容器通过commit提交为1个镜像！我们以后就使⽤我们修改过的镜像即可，这就是我们⾃⼰的⼀个镜像</span></span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1FW1P"><img src="https://z3.ax1x.com/2021/07/17/W1FW1P.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1FW1P.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1FW1P.png"></a></p>
<p>学习⽅式说明：理解概念，但是⼀定要实践，最后实践和理论相结合，⼀次搞定</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">如果你想要保存当前的容器状态，就可以通过commit提交 ，获得⼀个镜像</span><br><span class="line">就好⽐vm的快照</span><br></pre></td></tr></table></figure>

<p><strong>到这⾥才算是⼊⻔！</strong></p>
<h2 id="容器数据卷"><a href="#容器数据卷" class="headerlink" title="容器数据卷"></a>容器数据卷</h2><h4 id="什么是容器数据卷"><a href="#什么是容器数据卷" class="headerlink" title="什么是容器数据卷"></a>什么是容器数据卷</h4><p><strong>docker的理念回顾</strong></p>
<p>将应⽤和环境打包成⼀个镜像！</p>
<p>数据？如果数据在容器中，容器⼀旦删除，数据就会丢失！==需求：数据可以持久化==</p>
<p>MySQL，容器删了，删库跑路！ ==需求：Mysql的数据可以存储在本地或者其他地⽅==</p>
<p>容器之间可以有数据共享的技术 ！Docker容器中产⽣的数据，同步到本地 ！</p>
<p>这就是卷技术！⽬录的挂载，将我们容器内的⽬录，挂载到linux！</p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1FI0g"><img src="https://z3.ax1x.com/2021/07/17/W1FI0g.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1FI0g.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1FI0g.png"></a></p>
<p><strong>总结：容器的持久化和同步操作！容器间也是可以数据共享的！</strong></p>
<h4 id="使用数据卷"><a href="#使用数据卷" class="headerlink" title="使用数据卷"></a>使用数据卷</h4><blockquote>
<p>方式一：直接使⽤命令来挂载 -v</p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">docker run -it -v 主机⽬录:容器⽬录 -P 主机端⼝:容器端⼝</span><br><span class="line">[root@192 home]# docker run -it -v /home/ceshi:/home centos /bin/bash</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 启动后可以通过docker inspect 容器id</span></span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1FHts"><img src="https://z3.ax1x.com/2021/07/17/W1FHts.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1FHts.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1FHts.png"></a></p>
<p>测试文件的同步</p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1FO10"><img src="https://z3.ax1x.com/2021/07/17/W1FO10.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1FO10.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1FO10.png"></a></p>
<p>再来测试！</p>
<ol>
<li><p>停⽌容器</p>
</li>
<li><p>在宿主机上修改⽂件</p>
</li>
<li><p>再次启动容器</p>
</li>
<li><p>发现容器内的⽂件修改同步</p>
</li>
</ol>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1kEjK"><img src="https://z3.ax1x.com/2021/07/17/W1kEjK.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1kEjK.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1kEjK.png"></a></p>
<p>好处：我们以后修改只需在本地修改即可，容器内会⾃动同步</p>
<h4 id="实战：安装Mysql"><a href="#实战：安装Mysql" class="headerlink" title="实战：安装Mysql"></a>实战：安装Mysql</h4><p>思考:mysql数据持久化问题 data</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 获取镜像</span></span><br><span class="line">[root@localhost ~]# docker pull mysql:5.7</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 运⾏容器，需要做数据挂载！启动mysql，需要配置密码的，要注意</span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 官⽅测试： docker run --name some-mysql-e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 启动我们的</span></span><br><span class="line">-d 后台运⾏</span><br><span class="line">-p 端⼝映射</span><br><span class="line">-v 数据卷挂载</span><br><span class="line">-e 环境配置</span><br><span class="line">--name 容器名字</span><br><span class="line"></span><br><span class="line">[root@192 home]# docker run -d -p 3310:3306 -v /home/mysql/conf:/etc/mysql/conf.d -v /home/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=80231hdd --name mysql01 mysql:5.7</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 启动成功之后在本地使⽤navicat链接测试</span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 本地的mysql -h -u -p 连接到服务器的3310，3310和容器内的3306 映射</span></span><br><span class="line">mysql -h 192.168.80.1 -P 3310 -uroot -p80231hdd</span><br></pre></td></tr></table></figure>

<p>假设我们将容器删除</p>
<p>发现，我们挂载到本地的数据卷 依旧没有丢失，这就实现了容器数据持久化功能</p>
<h4 id="具名挂载和匿名挂载"><a href="#具名挂载和匿名挂载" class="headerlink" title="具名挂载和匿名挂载"></a>具名挂载和匿名挂载</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 匿名挂载</span></span><br><span class="line">-v 容器内路径</span><br><span class="line">docker run -d -p --name ngnix01 -v /etc/ngnix</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash">查看所有的volume的情况</span></span><br><span class="line">[root@192 home]# docker volume ls</span><br><span class="line">DRIVER    VOLUME NAME</span><br><span class="line">local     af873ca78a40cf6e44f4ef6fecd54b1ff94e4d977fff958b460af233cf17aca9</span><br><span class="line">local     c639c329a03829240cdbb640770fcef4942bafb5130936042edea1ba5681d68d</span><br><span class="line"><span class="meta">#</span><span class="bash"> 这⾥发现，这种就是匿名挂载，我们在-v 的时只写了容器内的路径，没有写容器外的路径</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 具名挂载</span></span><br><span class="line">[root@192 home]# docker run -d -P --name nginx02 -v juming-nginx:/etc/nginx nginx</span><br><span class="line">d1f2cd8cf72210f6336fff4c817ca871de1efde6551db98c99757d042c61c6da</span><br><span class="line">[root@192 home]# docker volume ls</span><br><span class="line">DRIVER    VOLUME NAME</span><br><span class="line">local     af873ca78a40cf6e44f4ef6fecd54b1ff94e4d977fff958b460af233cf17aca9</span><br><span class="line">local     c639c329a03829240cdbb640770fcef4942bafb5130936042edea1ba5681d68d</span><br><span class="line">local     juming-nginx</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 通过 -v 卷名:容器内路径</span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 查看⼀下这个卷</span></span><br><span class="line">[root@192 home]# docker volume inspect juming-nginx</span><br><span class="line">[</span><br><span class="line">    &#123;</span><br><span class="line">        &quot;CreatedAt&quot;: &quot;2021-07-14T10:45:40-04:00&quot;,</span><br><span class="line">        &quot;Driver&quot;: &quot;local&quot;,</span><br><span class="line">        &quot;Labels&quot;: null,</span><br><span class="line">        &quot;Mountpoint&quot;: &quot;/var/lib/docker/volumes/juming-nginx/_data&quot;,</span><br><span class="line">        &quot;Name&quot;: &quot;juming-nginx&quot;,</span><br><span class="line">        &quot;Options&quot;: null,</span><br><span class="line">        &quot;Scope&quot;: &quot;local&quot;</span><br><span class="line">    &#125;</span><br><span class="line">]</span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1kZnO"><img src="https://z3.ax1x.com/2021/07/17/W1kZnO.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1kZnO.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1kZnO.png"></a></p>
<p>所有docker容器内的卷，没有指定⽬录的情况下都是在 <strong>/var/lib/docker/volumes/juming-nginx/_data</strong></p>
<p>我们通过具名挂载可以更⽅便的找到我们的卷，⼤多数情况使⽤<strong>具名挂载</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 如何确定是具名挂载还是匿名挂载</span></span><br><span class="line">-v 容器内路径 				#匿名挂载</span><br><span class="line">-v 卷名:容器内路径 			#具名挂载</span><br><span class="line">-v /宿主机的路径:容器内路径 	#指定路径挂载</span><br></pre></td></tr></table></figure>

<p>扩展：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 通过-v 容器内路径:加上ro/rw改变读写权限</span></span><br><span class="line">ro readonly		#只读</span><br><span class="line">re readwrite	#可读可写</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> ⼀旦设置了容器权限，容器对我们挂载出来的内容就有限定了</span></span><br><span class="line">docker run -d -P --name nginx01 -v juming-nginx:/etc/nginx:ro nginx</span><br><span class="line">docker run -d -P --name nginx01 -v juming-nginx:/etc/nginx:rw nginx</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash">ro 只要看到ro就说明这个路径只能通过宿主机来操作，容器内部是⽆法操作的</span></span><br></pre></td></tr></table></figure>

<h4 id="初识DockerFile"><a href="#初识DockerFile" class="headerlink" title="初识DockerFile"></a>初识DockerFile</h4><p>DockerFile就是⽤来构建docker镜像的构建⽂件！命令脚本！</p>
<p>通过这个脚本可以⽣成⼀个镜像，镜像是⼀层⼀层的，脚本⼀个个的命令，每个命令都是⼀层</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 创建⼀个dockerfile的⽂件，名字可以随机 建议Dockerfile</span></span><br><span class="line">[root@hecs-398933 etc]# cd /home</span><br><span class="line">[root@hecs-398933 home]# mkdir docker-test-volume</span><br><span class="line">[root@hecs-398933 home]# ls</span><br><span class="line">ceshi  docker-test-volume</span><br><span class="line">[root@hecs-398933 home]# cd docker-test-volume/</span><br><span class="line">[root@hecs-398933 docker-test-volume]# vim dockerfile1</span><br><span class="line">[root@hecs-398933 docker-test-volume]# cat dockerfile1</span><br><span class="line">FROM centos</span><br><span class="line">VOLUME [&quot;volume01&quot;,&quot;volume02&quot;]</span><br><span class="line">CMD echo&quot;---end----&quot;</span><br><span class="line">CMD /bin/bash</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">[root@192 docker-test-volume]# docker build -f /home/docker-test-volume/dockerfile1 -t yangyang/centos .</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> ⽂件中的内容 指令 参数</span></span><br><span class="line">FROM centos</span><br><span class="line">VOLUME [&quot;volume01&quot;,&quot;volume02&quot;]</span><br><span class="line">CMD echo&quot;---end----&quot;</span><br><span class="line">CMD /bin/bash</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 每个命令都是镜像的⼀层</span></span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1kuAH"><img src="https://z3.ax1x.com/2021/07/17/W1kuAH.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1kuAH.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1kuAH.png"></a></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">启动一个自己写的容器</span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1k13t"><img src="https://z3.ax1x.com/2021/07/17/W1k13t.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1k13t.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1k13t.png"></a></p>
<p>这个卷和外部有⼀个同步的⽬录</p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1kJu8"><img src="https://z3.ax1x.com/2021/07/17/W1kJu8.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1kJu8.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1kJu8.png"></a></p>
<p>查看卷挂载的路径</p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1kUEQ"><img src="https://z3.ax1x.com/2021/07/17/W1kUEQ.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1kUEQ.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1kUEQ.png"></a></p>
<p>假设构建镜像时没有挂载卷，要⼿动挂载镜像         -v 卷名:容器内路径！</p>
<h4 id="数据卷容器"><a href="#数据卷容器" class="headerlink" title="数据卷容器"></a>数据卷容器</h4><p>多个mysql同步数据</p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1kyuT"><img src="https://z3.ax1x.com/2021/07/17/W1kyuT.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1kyuT.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1kyuT.png"></a></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -it --name docker02 --volumes-from docker01 kuangshen/centos:1.0</span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1k6DU"><img src="https://z3.ax1x.com/2021/07/17/W1k6DU.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1k6DU.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1k6DU.png"></a></p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1kcbF"><img src="https://z3.ax1x.com/2021/07/17/W1kcbF.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1kcbF.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1kcbF.png"></a></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 测试，可以删除docker01，查看⼀下docker02和docker03是否可以访问这个⽂件</span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 测试依旧可以访问</span></span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1k5gx"><img src="https://z3.ax1x.com/2021/07/17/W1k5gx.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1k5gx.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1k5gx.png"></a></p>
<p>多个mysql实现数据共享</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[root@192 home]# docker run -d -p 3310:3306 -v /home/mysql/conf:/etc/mysql/conf.d -v /home/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=80231hdd --name mysql01 mysql:5.7</span><br><span class="line"></span><br><span class="line">[root@192 home]# docker run -d -p 3310:3306  -e MYSQL_ROOT_PASSWORD=80231hdd --name mysql02 --volumes-from mysql:5.7</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 这个时候可以实现两个容器同步</span></span><br></pre></td></tr></table></figure>

<p>结论:</p>
<p>容器之间信息传递，数据卷容器的⽣命周期可以持续到没有容器使⽤为⽌</p>
<p>但是⼀旦持久化到了本地，知这时候本地的数据是不会删除的</p>
<h2 id="DockerFile"><a href="#DockerFile" class="headerlink" title="DockerFile"></a>DockerFile</h2><h4 id="DockerFile的介绍"><a href="#DockerFile的介绍" class="headerlink" title="DockerFile的介绍"></a>DockerFile的介绍</h4><p>dockerfile是⽤来构建docker镜像的⽂件</p>
<p>构建步骤:</p>
<ol>
<li><p>编写⼀个 dockerfile ⽂件</p>
</li>
<li><p><code>docker build</code> 构建⼀个镜像</p>
</li>
<li><p><code>docker run</code> 运⾏镜像</p>
</li>
<li><p><code>docker push</code> 发布镜像（dockerhub、 阿⾥云镜像仓库！）</p>
</li>
</ol>
<blockquote>
<p>查看⼀下官⽅</p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1kLUH"><img src="https://z3.ax1x.com/2021/07/17/W1kLUH.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1kLUH.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1kLUH.png"></a></p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1kO5d"><img src="https://z3.ax1x.com/2021/07/17/W1kO5d.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1kO5d.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1kO5d.png"></a></p>
<p>很多官⽅的镜像都是基础包，很多功能都没有，我么通常⾃⼰搭建⾃⼰的镜像</p>
<p>官方既然可以制作镜像我们也可以！</p>
</blockquote>
<h4 id="DockerFile构建过程"><a href="#DockerFile构建过程" class="headerlink" title="DockerFile构建过程"></a>DockerFile构建过程</h4><p>基础知识：</p>
<ol>
<li><p>每个保留关键字（指令）都是⼤写字⺟<a target="_blank" rel="noopener" href="https://imgtu.com/i/W1kzxP"><img src="https://z3.ax1x.com/2021/07/17/W1kzxP.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1kzxP.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1kzxP.png"></a></p>
</li>
<li><p>执⾏从上到下的顺序</p>
</li>
<li><p>#表示注释</p>
</li>
<li><p>每个指令都会创建提交⼀个新的镜像层，并提交！</p>
</li>
</ol>
<p><a target="_blank" rel="noopener" href="https://imagelol.com/image/Ied0HO"><img src="https://s3.jpg.cm/2021/07/17/Ied0HO.png" class="lazyload placeholder" data-srcset="https://s3.jpg.cm/2021/07/17/Ied0HO.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="Ied0HO.png"></a></p>
<p>DockerFIle是⾯向开发的，我们以后要发布项⽬，做镜像，就要编写dockefile，这个⽂件⼗分简单！</p>
<p>Docker镜像 逐渐成为了企业交付的标准，必须要掌握！</p>
<p>步骤：开发，部署，运维。。。缺⼀不可</p>
<p>Docker File：构建⽂件，定义了⼀切的步骤，源代码</p>
<p>Dockerimage：通过Docjerfile构建⽣成的镜像，最终运⾏的产品，原来是⼀个jar包，war包</p>
<p>Docker容器：镜像运⾏起来提供服务器</p>
<h4 id="DockerFile指令"><a href="#DockerFile指令" class="headerlink" title="DockerFile指令"></a>DockerFile指令</h4><p>以前的话⽤别⼈的 ，现在我们知道这些指令后就创建⾃⼰的镜像</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">FROM 				# 基础镜像 centos ubuntu，⼀切从这⾥构建</span><br><span class="line">MAINTAINER 			# 镜像是谁写的，姓名+邮箱</span><br><span class="line">RUN 				# Docker镜像构建时需要运⾏的命令</span><br><span class="line">ADD 				# 步骤， tomacat镜像，这个tomcat压缩包（添加内容）</span><br><span class="line">WORKDIR				 # 镜像的⼯作目录 /bin/bash</span><br><span class="line">VOLUME 			# 挂载的⽬录</span><br><span class="line">EXPOSE 			# 暴露端⼝，保留端⼝配置</span><br><span class="line">CMD 			# 指定这个容器的时候要运⾏的命令 cmd echo，只有最后⼀个会⽣效，可被替代</span><br><span class="line">ENTRYPOINT 		# 指定这个容器的时候要运⾏的命令 ，可以追加命令</span><br><span class="line">ONBUILD 		# 当构建⼀个被继承的DockerFile 这个时候就会运⾏ONBUILD的指令..触发指令</span><br><span class="line">COPY 			# 类似ADD命令 ，将我们的⽂件拷⻉到镜像中</span><br><span class="line">ENV 			# 构建的时候设置环境变量</span><br></pre></td></tr></table></figure>

<p><img src="https://z3.ax1x.com/2021/07/17/W1kzxP.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1kzxP.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1kzxP.png"></p>
<h4 id="实战测试"><a href="#实战测试" class="headerlink" title="实战测试"></a>实战测试</h4><p>DockerHub中99%的镜像都是从这个基础镜像过来的<code>FROM scratch</code>，然后配置需要的软件和配置来进⾏的构建的</p>
<p><a target="_blank" rel="noopener" href="https://imagelol.com/image/Ied2gw"><img src="https://s3.jpg.cm/2021/07/17/Ied2gw.png" class="lazyload placeholder" data-srcset="https://s3.jpg.cm/2021/07/17/Ied2gw.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="Ied2gw.png"></a></p>
<blockquote>
<p>创建⼀个⾃⼰的centos</p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 1、编写DockerFile的文件</span></span><br><span class="line">[root@hecs-398933 dockerfile]# vim mydockerfile-centos</span><br><span class="line">[root@hecs-398933 dockerfile]# cat mydockerfile-centos </span><br><span class="line">FROM centos</span><br><span class="line">MAINTAINER yangyang&lt;2985409357@qq.com&gt;</span><br><span class="line">ENV MYPATH /usr/local</span><br><span class="line">WORKDIR $MYPATH</span><br><span class="line"></span><br><span class="line">RUN yum -y install vim</span><br><span class="line">RUN yum -y install net-tools</span><br><span class="line">EXPOSE 80</span><br><span class="line"></span><br><span class="line">CMD echo $MYPATH</span><br><span class="line">CMD echo&quot;--end----&quot;</span><br><span class="line">CMD /bin/bash</span><br><span class="line"><span class="meta">#</span><span class="bash"> 2、通过这个文件构建镜像</span></span><br><span class="line">[root@hecs-398933 dockerfile]# docker build -f mydockerfile-centos -t mycentos:1.0 .</span><br><span class="line">Successfully built 05720b3305d4</span><br><span class="line">Successfully tagged mycentos:1.0</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 3、测试运行</span></span><br><span class="line">[root@hecs-398933 dockerfile]# docker run -it mycentos:1.0</span><br><span class="line">[root@ad9b8b00f1e4 local]# pwd</span><br><span class="line">/usr/local</span><br><span class="line">[root@ad9b8b00f1e4 local]# ifconfig</span><br><span class="line">eth0: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt;  mtu 1500</span><br><span class="line">        inet 172.17.0.3  netmask 255.255.0.0  broadcast 172.17.255.255</span><br><span class="line">        ether 02:42:ac:11:00:03  txqueuelen 0  (Ethernet)</span><br><span class="line">        RX packets 8  bytes 656 (656.0 B)</span><br><span class="line">        RX errors 0  dropped 0  overruns 0  frame 0</span><br><span class="line">        TX packets 0  bytes 0 (0.0 B)</span><br><span class="line">        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0</span><br><span class="line"></span><br><span class="line">lo: flags=73&lt;UP,LOOPBACK,RUNNING&gt;  mtu 65536</span><br><span class="line">        inet 127.0.0.1  netmask 255.0.0.0</span><br><span class="line">        loop  txqueuelen 1000  (Local Loopback)</span><br><span class="line">        RX packets 0  bytes 0 (0.0 B)</span><br><span class="line">        RX errors 0  dropped 0  overruns 0  frame 0</span><br><span class="line">        TX packets 0  bytes 0 (0.0 B)</span><br><span class="line">        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0</span><br><span class="line"></span><br><span class="line">[root@ad9b8b00f1e4 local]# vim test</span><br></pre></td></tr></table></figure>

<p>原来的：原生centos<a target="_blank" rel="noopener" href="https://imgtu.com/i/W1AEPs"><img src="https://z3.ax1x.com/2021/07/17/W1AEPs.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1AEPs.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1AEPs.png"></a></p>
<p>现在的：我们增加之后的镜像<a target="_blank" rel="noopener" href="https://imgtu.com/i/W1Aex0"><img src="https://z3.ax1x.com/2021/07/17/W1Aex0.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1Aex0.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1Aex0.png"></a></p>
<p>我们可以列出本地镜像的变更历史,</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">[root@hecs-398933 dockerfile]# docker history  05720b3305d4</span><br><span class="line">IMAGE          CREATED         CREATED BY                                      SIZE      COMMENT</span><br><span class="line">05720b3305d4   5 minutes ago   /bin/sh -c #(nop)  CMD [&quot;/bin/sh&quot; &quot;-c&quot; &quot;/bin…   0B        </span><br><span class="line">6ac7ca029143   5 minutes ago   /bin/sh -c #(nop)  CMD [&quot;/bin/sh&quot; &quot;-c&quot; &quot;echo…   0B        </span><br><span class="line">b57b3fb3cce0   5 minutes ago   /bin/sh -c #(nop)  CMD [&quot;/bin/sh&quot; &quot;-c&quot; &quot;echo…   0B        </span><br><span class="line">f719aadee667   5 minutes ago   /bin/sh -c #(nop)  EXPOSE 80                    0B        </span><br><span class="line">dd5f52fd2573   5 minutes ago   /bin/sh -c yum -y install net-tools             121MB     </span><br><span class="line">0a0bdb0cb1cb   5 minutes ago   /bin/sh -c yum -y install vim                   176MB     </span><br><span class="line">9b8cfa6b86f6   7 minutes ago   /bin/sh -c #(nop) WORKDIR /usr/local            0B        </span><br><span class="line">d66e9ed3f2c4   7 minutes ago   /bin/sh -c #(nop)  ENV MYPATH=/usr/local        0B        </span><br><span class="line">bd951f8f8aab   7 minutes ago   /bin/sh -c #(nop)  MAINTAINER yangyang&lt;29854…   0B        </span><br><span class="line">75835a67d134   2 years ago     /bin/sh -c #(nop)  CMD [&quot;/bin/bash&quot;]            0B        </span><br><span class="line">&lt;missing&gt;      2 years ago     /bin/sh -c #(nop)  LABEL org.label-schema.sc…   0B        </span><br><span class="line">&lt;missing&gt;      2 years ago     /bin/sh -c #(nop) ADD file:fbe9badfd2790f074…   200MB    </span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1AKqU"><img src="https://z3.ax1x.com/2021/07/17/W1AKqU.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1AKqU.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1AKqU.png"></a></p>
<p>从这我拿到⼀个docker就知道他是怎么做的了</p>
<hr>
<blockquote>
<p>CMD 和 ENTRYPOINT的区别</p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">CMD 		# 指定这个容器的时候要运⾏的命令 cmd echo，只有最后⼀个会⽣效，可被替代</span><br><span class="line">ENTRYPOINT 	# 指定这个容器的时候要运⾏的命令 ，可以追加命令</span><br></pre></td></tr></table></figure>

<p>测试cmd</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 编写dockerfile⽂件</span></span><br><span class="line">[root@localhost dockerfile]# vim dockerfile-cmd-test </span><br><span class="line">FROM centos</span><br><span class="line">CMD [&quot;ls&quot;,&quot;-a&quot;]</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 构建镜像</span></span><br><span class="line">[root@localhost dockerfile]# docker build -f dockerfile-cmd-test -t cmdtest .</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> run运⾏，发现我们的ls -a命令⽣效了</span></span><br><span class="line">[root@localhost dockerfile]# docker run cmdtest</span><br><span class="line">.</span><br><span class="line">..</span><br><span class="line">.dockerenv</span><br><span class="line">bin</span><br><span class="line">dev</span><br><span class="line">etc</span><br><span class="line">home</span><br><span class="line">lib</span><br><span class="line">lib64</span><br><span class="line">lost+found</span><br><span class="line">media</span><br><span class="line">mnt</span><br><span class="line">opt</span><br><span class="line">proc</span><br><span class="line">root</span><br><span class="line">run</span><br><span class="line">sbin</span><br><span class="line">srv</span><br><span class="line">sys</span><br><span class="line">tmp</span><br><span class="line">usr</span><br><span class="line">var</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 想追加命令-l</span></span><br><span class="line">[root@hecs-398933 dockerfile]# docker run a1c658d03140 -l</span><br><span class="line">docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: &quot;-l&quot;: executable file not found in $PATH: unknown.</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> cmd情况下 -l替换了CMD[<span class="string">&quot;ls&quot;</span>,<span class="string">&quot;-a&quot;</span>]命令，-l不是命令所以报错</span></span><br></pre></td></tr></table></figure>

<p>测试ENTRYPOINT</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 编写dockerfile⽂件</span></span><br><span class="line">[root@localhost dockerfile]# vim dockerfile-entrypoint-test</span><br><span class="line">FROM centos</span><br><span class="line">ENTRYPOINT [&quot;ls&quot;,&quot;-a&quot;]</span><br><span class="line"><span class="meta">#</span><span class="bash"> 构建</span></span><br><span class="line">[root@localhost dockerfile]# docker build -f dockerfile-entrypoint-test -t entrypoint-test .</span><br><span class="line">Sending build context to Docker daemon 16.9kB</span><br><span class="line">Step 1/2 : FROM centos</span><br><span class="line"><span class="meta">---&gt;</span><span class="bash"> 300e315adb2f</span></span><br><span class="line">Step 2/2 : ENTRYPOINT [&quot;ls&quot;,&quot;-a&quot;]</span><br><span class="line"><span class="meta">---&gt;</span><span class="bash"> Using cache</span></span><br><span class="line"><span class="meta">---&gt;</span><span class="bash"> 2dbbec8e487f</span></span><br><span class="line">Successfully built 2dbbec8e487f</span><br><span class="line">Successfully tagged entrypoint-test:latest</span><br><span class="line"><span class="meta">#</span><span class="bash"> 运行测试</span></span><br><span class="line">[root@localhost dockerfile]# docker run 2dbbec8e487f</span><br><span class="line">.</span><br><span class="line">..</span><br><span class="line">.dockerenv</span><br><span class="line">bin</span><br><span class="line">dev</span><br><span class="line">etc</span><br><span class="line">home</span><br><span class="line">lib</span><br><span class="line">lib64</span><br><span class="line">lost+found</span><br><span class="line">media</span><br><span class="line">mnt</span><br><span class="line">opt</span><br><span class="line">proc</span><br><span class="line">root</span><br><span class="line">run</span><br><span class="line">sbin</span><br><span class="line">srv</span><br><span class="line">sys</span><br><span class="line">tmp</span><br><span class="line">usr</span><br><span class="line">var</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 我们的命令是直接拼接到后⾯的</span></span><br><span class="line">[root@localhost dockerfile]# docker run 2dbbec8e487f -l</span><br><span class="line">total 56</span><br><span class="line">drwxr-xr-x. 1 root root 6 Apr 7 13:19 .</span><br><span class="line">drwxr-xr-x. 1 root root 6 Apr 7 13:19 ..</span><br><span class="line">-rwxr-xr-x. 1 root root 0 Apr 7 13:19 .dockerenv</span><br><span class="line">lrwxrwxrwx. 1 root root 7 Nov 3 15:22 bin -&gt; usr/bin</span><br><span class="line">drwxr-xr-x. 5 root root 340 Apr 7 13:19 dev</span><br><span class="line">drwxr-xr-x. 1 root root 66 Apr 7 13:19 etc</span><br><span class="line">drwxr-xr-x. 2 root root 6 Nov 3 15:22 home</span><br><span class="line">lrwxrwxrwx. 1 root root 7 Nov 3 15:22 lib -&gt; usr/lib</span><br><span class="line">lrwxrwxrwx. 1 root root 9 Nov 3 15:22 lib64 -&gt; usr/lib64</span><br><span class="line">drwx------. 2 root root 6 Dec 4 17:37 lost+found</span><br><span class="line">drwxr-xr-x. 2 root root 6 Nov 3 15:22 media</span><br><span class="line">drwxr-xr-x. 2 root root 6 Nov 3 15:22 mnt</span><br><span class="line">drwxr-xr-x. 2 root root 6 Nov 3 15:22 opt</span><br><span class="line">dr-xr-xr-x. 284 root root 0 Apr 7 13:19 proc</span><br><span class="line">dr-xr-x---. 2 root root 162 Dec 4 17:37 root</span><br><span class="line">drwxr-xr-x. 11 root root 163 Dec 4 17:37 run</span><br><span class="line">lrwxrwxrwx. 1 root root 8 Nov 3 15:22 sbin -&gt; usr/sbin</span><br><span class="line">drwxr-xr-x. 2 root root 6 Nov 3 15:22 srv</span><br><span class="line">dr-xr-xr-x. 13 root root 0 Apr 7 08:01 sys</span><br></pre></td></tr></table></figure>

<p>DockerFile中很多命令都⼗分相似，我们都需要了解他们的区别，最好是进⾏测试</p>
<h4 id="实战：Tomcat镜像"><a href="#实战：Tomcat镜像" class="headerlink" title="实战：Tomcat镜像"></a>实战：Tomcat镜像</h4><ol>
<li><p>准备tomacat镜像压缩包，jdk压缩包！</p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1AGGR"><img src="https://z3.ax1x.com/2021/07/17/W1AGGR.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1AGGR.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1AGGR.png"></a></p>
</li>
<li><p>编写dockerfile⽂件，官⽅命名<code>Dockerfile</code>，build时会⾃动寻找这个⽂件，不需要-f指定了</p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1AUsK"><img src="https://z3.ax1x.com/2021/07/17/W1AUsK.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1AUsK.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1AUsK.png"></a></p>
</li>
<li><p>构建镜像</p>
<p><code># docker build -t diy:1.0 .</code> </p>
</li>
<li><p>启动镜像</p>
</li>
<li><p><a target="_blank" rel="noopener" href="https://imagelol.com/image/Iedhvk"><img src="https://s3.jpg.cm/2021/07/17/Iedhvk.png" class="lazyload placeholder" data-srcset="https://s3.jpg.cm/2021/07/17/Iedhvk.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="Iedhvk.png"></a></p>
</li>
<li><p>访问测试</p>
</li>
<li><p>发布项⽬（由于做了卷挂载，我们直接在本地编写项⽬，就可以发布了）</p>
<p><a target="_blank" rel="noopener" href="https://imagelol.com/image/IedKXi"><img src="https://s3.jpg.cm/2021/07/17/IedKXi.png" class="lazyload placeholder" data-srcset="https://s3.jpg.cm/2021/07/17/IedKXi.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="IedKXi.png"></a></p>
</li>
</ol>
<p>我们以后开发的步骤:需要掌握Dokcerfile的编写! 我们之后的一切都是使用docker镜像来发布运行!</p>
<h4 id="发布自己的镜像"><a href="#发布自己的镜像" class="headerlink" title="发布自己的镜像"></a>发布自己的镜像</h4><blockquote>
<p>Dckerhub</p>
</blockquote>
<ol>
<li><p>地址<a target="_blank" rel="noopener" href="https://registry.hub.docker.com/">https://registry.hub.docker.com</a> 注册⾃⼰的账号</p>
</li>
<li><p>确定账号可以登陆</p>
</li>
<li><p>在我们的服务器上提交⾃⼰的镜像</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost dockerfile]# docker login --help</span><br><span class="line"></span><br><span class="line">Usage: docker login [OPTIONS] [SERVER]</span><br><span class="line"></span><br><span class="line">Log in to a Docker registry.</span><br><span class="line">If no server is specified, the default is defined by the daemon.</span><br><span class="line"></span><br><span class="line">Options:</span><br><span class="line"> -p, --password string 		Password</span><br><span class="line"> 	 --password-stdin 		Take the password from stdin</span><br><span class="line"> -u, --username string 		Username</span><br><span class="line"> </span><br><span class="line"> [root@hecs-398933 tomcat]# docker login -u yangyanglinux</span><br><span class="line">Password: </span><br><span class="line">WARNING! Your password will be stored unencrypted in /root/.docker/config.json.</span><br><span class="line">Configure a credential helper to remove this warning. See</span><br><span class="line">https://docs.docker.com/engine/reference/commandline/login/#credentials-store</span><br><span class="line"></span><br><span class="line">Login Succeeded</span><br></pre></td></tr></table></figure>

<ol start="4">
<li><p>登陆完毕后就可以提交⾃⼰的镜像了，就是⼀步push</p>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/yanpenglei/article/details/78948537">https://blog.csdn.net/yanpenglei/article/details/78948537</a></p>
<p><a target="_blank" rel="noopener" href="https://imagelol.com/image/Iedjie"><img src="https://s3.jpg.cm/2021/07/17/Iedjie.png" class="lazyload placeholder" data-srcset="https://s3.jpg.cm/2021/07/17/Iedjie.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="Iedjie.png"></a></p>
</li>
</ol>
</li>
</ol>
<p>提交的时候也是按照层级来进⾏提交</p>
<hr>
<blockquote>
<p>发布阿⾥云镜像服务(可以参考官方网址)</p>
</blockquote>
<ol>
<li><p>登陆阿⾥云</p>
</li>
<li><p>找到容器镜像服务</p>
</li>
<li><p>创建命名空间</p>
</li>
<li><p>创建容器镜像</p>
</li>
<li><p>浏览阿⾥云信息</p>
</li>
</ol>
<h4 id="小结-1"><a href="#小结-1" class="headerlink" title="小结"></a>小结</h4><p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1EPQx"><img src="https://z3.ax1x.com/2021/07/17/W1EPQx.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1EPQx.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1EPQx.png"></a></p>
<h2 id="Docker网络"><a href="#Docker网络" class="headerlink" title="Docker网络"></a>Docker网络</h2><h4 id="理解Docker0网络"><a href="#理解Docker0网络" class="headerlink" title="理解Docker0网络"></a>理解Docker0网络</h4><p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1EEwD"><img src="https://z3.ax1x.com/2021/07/17/W1EEwD.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1EEwD.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1EEwD.png"></a></p>
<p>三个网络</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> docker是如何处理容器⽹络访问的</span></span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://imagelol.com/image/Ied9ey"><img src="https://s3.jpg.cm/2021/07/17/Ied9ey.png" class="lazyload placeholder" data-srcset="https://s3.jpg.cm/2021/07/17/Ied9ey.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="Ied9ey.png"></a></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">[root@hecs-398933 /]# docker run -d -P --name tomcat01 tomcat</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 查看容器内部网路地址	ip addr   发现容器启动的时候会得到eth0@if35这样的IP地址，docker分配的</span></span><br><span class="line">[root@hecs-398933 /]# docker exec -it tomcat01 ip addr</span><br><span class="line">1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000</span><br><span class="line">    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00</span><br><span class="line">    inet 127.0.0.1/8 scope host lo</span><br><span class="line">       valid_lft forever preferred_lft forever</span><br><span class="line">36: eth0@if37: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc noqueue state UP group default </span><br><span class="line">    link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0</span><br><span class="line">    inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0</span><br><span class="line">       valid_lft forever preferred_lft forever</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash">思考 linux服务器能不能ping通</span></span><br><span class="line">[root@localhost dockerfile]# ping 172.17.0.2</span><br><span class="line">PING 172.17.0.2 (172.17.0.2) 56(84) bytes of data.</span><br><span class="line">64 bytes from 172.17.0.2: icmp_seq=1 ttl=64 time=0.106 ms</span><br><span class="line">64 bytes from 172.17.0.2: icmp_seq=2 ttl=64 time=0.062 ms</span><br><span class="line">64 bytes from 172.17.0.2: icmp_seq=3 ttl=64 time=0.081 ms</span><br><span class="line">64 bytes from 172.17.0.2: icmp_seq=4 ttl=64 time=0.067 ms</span><br></pre></td></tr></table></figure>



<blockquote>
<p>原理：</p>
</blockquote>
<ol>
<li><p>我们每启动⼀个docker容器，docker就会给docker容器分配个ip，我们只要安装了docker，就会有⼀个⽹卡docker0，桥接模式，使⽤的技术是evth-pair技术</p>
<p>==再次测试==</p>
<p><a target="_blank" rel="noopener" href="https://imagelol.com/image/IedTsr"><img src="https://s3.jpg.cm/2021/07/17/IedTsr.png" class="lazyload placeholder" data-srcset="https://s3.jpg.cm/2021/07/17/IedTsr.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="IedTsr.png"></a></p>
</li>
<li><p>再启动⼀个容器,发现⼜多了⼀对⽹卡</p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1EMlt"><img src="https://z3.ax1x.com/2021/07/17/W1EMlt.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1EMlt.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1EMlt.png"></a></p>
</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 我们发现这些容器带来的技术都是⼀对⼀对的</span></span><br><span class="line"><span class="meta">#</span><span class="bash"> evth-pair 就是⼀对的虚拟设备接⼝，他们都是成对的，⼀段连着协议，⼀段彼此相连</span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 正因为有这个特性，通常⽤evth-pair技术充当⼀个桥梁，连接各种虚拟设备</span></span><br><span class="line"><span class="meta">#</span><span class="bash"> openstack，DOcker容器之间的连接，OVS的连接，都是使⽤evth-pair的技术</span></span><br></pre></td></tr></table></figure>

<ol start="3">
<li><p>我们来测试tomcat01和tomcat02之间是否能ping通</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">[root@hecs-398933 ~]# docker exec -it tomcat01 ping 172.17.0.3</span><br><span class="line">PING 172.17.0.3 (172.17.0.3) 56(84) bytes of data.</span><br><span class="line">64 bytes from 172.17.0.3: icmp_seq=1 ttl=64 time=0.076 ms</span><br><span class="line">64 bytes from 172.17.0.3: icmp_seq=2 ttl=64 time=0.053 ms</span><br><span class="line">64 bytes from 172.17.0.3: icmp_seq=3 ttl=64 time=0.052 ms</span><br><span class="line">64 bytes from 172.17.0.3: icmp_seq=4 ttl=64 time=0.052 ms</span><br><span class="line">64 bytes from 172.17.0.3: icmp_seq=5 ttl=64 time=0.050 ms</span><br><span class="line">64 bytes from 172.17.0.3: icmp_seq=6 ttl=64 time=0.034 ms</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 结论容器之间是可以互相ping通的</span></span><br></pre></td></tr></table></figure>

<p>网络图：</p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1EYkQ"><img src="https://z3.ax1x.com/2021/07/17/W1EYkQ.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1EYkQ.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1EYkQ.png"></a></p>
</li>
</ol>
<p>结论：tomcat01和tomcat02是公⽤的1个交换机，docker0</p>
<p>所有容器不指定⽹络的情况下，都是docker0路由的，docker会给我们的容器分配⼀个默认的可⽤ip</p>
<hr>
<blockquote>
<p>⼩结</p>
</blockquote>
<p>Docker使⽤的是linux的桥接，宿主机中是⼀个Docker容器的⽹桥 docker0</p>
<p><a target="_blank" rel="noopener" href="https://imagelol.com/image/Iedah5"><img src="https://s3.jpg.cm/2021/07/17/Iedah5.png" class="lazyload placeholder" data-srcset="https://s3.jpg.cm/2021/07/17/Iedah5.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="Iedah5.png"></a></p>
<p>Docker中的所有的⽹络接⼝都是虚拟的，虚拟的转发效率⾼！（内⽹传递⽂件！）</p>
<p>只要容器删除，对应的⽹桥就没了</p>
<p><a target="_blank" rel="noopener" href="https://imagelol.com/image/IedxWC"><img src="https://s3.jpg.cm/2021/07/17/IedxWC.png" class="lazyload placeholder" data-srcset="https://s3.jpg.cm/2021/07/17/IedxWC.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="IedxWC.png"></a></p>
<h4 id="–link"><a href="#–link" class="headerlink" title="–link"></a>–link</h4><blockquote>
<p>思考：我们编写了⼀个微服务 database url=ip，项⽬不重启，数据库ip换了，我们希望可以通过名字访问服务</p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost dockerfile]# docker exec -it tomcat02 ping tomcat01</span><br><span class="line">ping: tomcat01: Name or service not known</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash">如何解决呢</span></span><br><span class="line">[root@localhost dockerfile]# docker exec -it tomcat02 ping tomcat01</span><br><span class="line">ping: tomcat01: Name or service not known</span><br><span class="line"><span class="meta">#</span><span class="bash"> 通过--link就可以解决了</span></span><br><span class="line">docker run -it --name tomcat03 --link tomcat02 tomcat</span><br><span class="line">[root@localhost dockerfile]# docker exec -it tomcat03 ping tomcat02</span><br><span class="line">PING tomcat02 (172.17.0.3) 56(84) bytes of data.</span><br><span class="line">64 bytes from tomcat02 (172.17.0.3): icmp_seq=1 ttl=64 time=0.131 ms</span><br><span class="line">64 bytes from tomcat02 (172.17.0.3): icmp_seq=2 ttl=64 time=0.135 ms</span><br><span class="line">64 bytes from tomcat02 (172.17.0.3): icmp_seq=3 ttl=64 time=0.120 ms</span><br><span class="line">ç64 bytes from tomcat02 (172.17.0.3): icmp_seq=4 ttl=64 time=0.091 ms</span><br><span class="line">^C</span><br><span class="line">--- tomcat02 ping statistics ---</span><br><span class="line">4 packets transmitted, 4 received, 0% packet loss, time 68ms</span><br><span class="line">rtt min/avg/max/mdev = 0.091/0.119/0.135/0.018 m</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 反向可以ping通嘛？不可以</span></span><br></pre></td></tr></table></figure>

<p>探究inspect</p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1Eapn"><img src="https://z3.ax1x.com/2021/07/17/W1Eapn.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1Eapn.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1Eapn.png"></a></p>
<p>其实tomacat03就是在本地配置了tomcat02？</p>
<p><a target="_blank" rel="noopener" href="https://imgtu.com/i/W1E0XV"><img src="https://z3.ax1x.com/2021/07/17/W1E0XV.png" class="lazyload placeholder" data-srcset="https://z3.ax1x.com/2021/07/17/W1E0XV.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="W1E0XV.png"></a></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 查看hosts配置</span></span><br><span class="line">[root@localhost dockerfile]# docker exec -it tomcat03 cat /etc/hosts</span><br><span class="line">127.0.0.1 localhost</span><br><span class="line">::1 localhost ip6-localhost ip6-loopback</span><br><span class="line">fe00::0 ip6-localnet</span><br><span class="line">ff00::0 ip6-mcastprefix</span><br><span class="line">ff02::1 ip6-allnodes</span><br><span class="line">ff02::2 ip6-allrouters</span><br><span class="line">172.17.0.3 tomcat02 2110f95268bc</span><br><span class="line">172.17.0.4 896c41fa1fd8</span><br></pre></td></tr></table></figure>

<p>–link在hosts中增加了</p>
<p>⾃定义⽹络！不适用docker0</p>
<p>docker0的问题：不⽀持容器名访问</p>
<h4 id="自定义网络"><a href="#自定义网络" class="headerlink" title="自定义网络"></a>自定义网络</h4><blockquote>
<p>查看所有的docker⽹络</p>
</blockquote>
<p><a target="_blank" rel="noopener" href="https://imagelol.com/image/IedDJt"><img src="https://s3.jpg.cm/2021/07/17/IedDJt.png" class="lazyload placeholder" data-srcset="https://s3.jpg.cm/2021/07/17/IedDJt.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="IedDJt.png"></a></p>
<p><strong>⽹络模式</strong></p>
<p>bridge：桥接模式 docker（默认）⾃⼰创建</p>
<p>none：不配置⽹络</p>
<p>host：主机模式，和宿主机共享⽹络</p>
<p><strong>测试</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 我们直接启动的命令 --net bridge，⽽这个就是我们的docker0</span></span><br><span class="line">docker run -d -p --name tomcat01 tomcat</span><br><span class="line">docker run -d -p --name tomcat01 --net bridge tomcat</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash">docker0特点：默认的，域名不能访问， --link可以打通连接</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash">⾃定义⼀个⽹络</span></span><br><span class="line"><span class="meta">#</span><span class="bash"> --driver bridge</span></span><br><span class="line"><span class="meta">#</span><span class="bash"> --subnet 192.168.0.0/16</span></span><br><span class="line"><span class="meta">#</span><span class="bash"> --gatway 192.168.0.1/16</span></span><br><span class="line"></span><br><span class="line">[root@localhost dockerfile]# docker network create --driver bridge --subnet 192.168.0.0/16 --gateway 192.168.0.1 mynet</span><br><span class="line">e727a0331cbda99de11c1e2cf6b2937f57cbe0a3f66c9ce8633119c832d33844</span><br><span class="line">[root@localhost dockerfile]# docker network ls</span><br><span class="line">NETWORK ID NAME DRIVER SCOPE</span><br><span class="line">3200030a164b bridge bridge local</span><br><span class="line">8983ea6cf3a0 host host local</span><br><span class="line">e727a0331cbd mynet bridge local</span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://imagelol.com/image/IedMzR"><img src="https://s3.jpg.cm/2021/07/17/IedMzR.png" class="lazyload placeholder" data-srcset="https://s3.jpg.cm/2021/07/17/IedMzR.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="IedMzR.png"></a></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">&quot;ConfigOnly&quot;: false,</span><br><span class="line"> &quot;Containers&quot;: &#123;</span><br><span class="line"> &quot;84823d554f25e0c981c235cdba256de5a83b636671fb65561516258e1f1e3280&quot;: &#123;</span><br><span class="line"> &quot;Name&quot;: &quot;tomcat-net-01&quot;,</span><br><span class="line"> &quot;EndpointID&quot;:</span><br><span class="line">&quot;c8c2d2839c94aee4ffeef6ce3e79e04ced247f08f8591227e1a9578285887cea&quot;,</span><br><span class="line"> &quot;MacAddress&quot;: &quot;02:42:c0:a8:00:02&quot;,</span><br><span class="line"> &quot;IPv4Address&quot;: &quot;192.168.0.2/16&quot;,</span><br><span class="line"> &quot;IPv6Address&quot;: &quot;&quot;</span><br><span class="line"> &#125;,</span><br><span class="line"> &quot;95ae06c0919d7b3114cde99d5e24282920e40a995574dd578071d9684d889cd2&quot;: &#123;</span><br><span class="line"> &quot;Name&quot;: &quot;tomcat-net-02&quot;,</span><br><span class="line"> &quot;EndpointID&quot;:</span><br><span class="line">&quot;e327e7d8f65e433e03756c54a136c1b5f3f6a97a1d862d9abd8dcb006aa18ded&quot;,</span><br><span class="line"> &quot;MacAddress&quot;: &quot;02:42:c0:a8:00:03&quot;,</span><br><span class="line"> &quot;IPv4Address&quot;: &quot;192.168.0.3/16&quot;,</span><br><span class="line"> &quot;IPv6Address&quot;: &quot;&quot;</span><br><span class="line"> &#125;</span><br><span class="line"> &#125;,</span><br><span class="line"> &quot;Options&quot;: &#123;&#125;,</span><br><span class="line"> &quot;Labels&quot;: &#123;&#125;</span><br><span class="line"> &#125;</span><br><span class="line"> ]</span><br><span class="line"><span class="meta"> </span></span><br><span class="line"><span class="meta"> #</span><span class="bash">再次测试ping连接，现在不使⽤---link也可以ping名字</span></span><br><span class="line">[root@localhost dockerfile]# docker exec -it tomcat-net-01 ping tomcat-net-02</span><br><span class="line">PING tomcat-net-02 (192.168.0.3) 56(84) bytes of data.</span><br><span class="line">64 bytes from tomcat-net-02.mynet (192.168.0.3): icmp_seq=1 ttl=64 time=0.304ms</span><br><span class="line">64 bytes from tomcat-net-02.mynet (192.168.0.3): icmp_seq=2 ttl=64 time=0.130ms</span><br><span class="line">64 bytes from tomcat-net-02.mynet (192.168.0.3): icmp_seq=3 ttl=64 time=0.130ms</span><br><span class="line">^C</span><br><span class="line">--- tomcat-net-02 ping statistics ---</span><br><span class="line">3 packets transmitted, 3 received, 0% packet loss, time 8ms</span><br><span class="line">rtt min/avg/max/mdev = 0.130/0.188/0.304/0.082 ms</span><br></pre></td></tr></table></figure>

<p>我们⾃定义的⽹络docker都已经维护好了对应关系，推荐平时这么使用网络</p>
<p>好处：</p>
<p>redis：不同的集群使⽤不同的⽹络，保证集群最安全</p>
<p><a target="_blank" rel="noopener" href="https://imagelol.com/image/IedZGz"><img src="https://s3.jpg.cm/2021/07/17/IedZGz.png" class="lazyload placeholder" data-srcset="https://s3.jpg.cm/2021/07/17/IedZGz.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="IedZGz.png"></a></p>
<h4 id="网络连通"><a href="#网络连通" class="headerlink" title="网络连通"></a>网络连通</h4><img src="https://www.z4a.net/images/2021/07/17/image-20210715205101677.png" class="lazyload placeholder" data-srcset="https://www.z4a.net/images/2021/07/17/image-20210715205101677.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="image-20210715205101677.png" border="0" />

<p><a target="_blank" rel="noopener" href="https://imagelol.com/image/IeeGcu"><img src="https://s3.jpg.cm/2021/07/17/IeeGcu.png" class="lazyload placeholder" data-srcset="https://s3.jpg.cm/2021/07/17/IeeGcu.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="IeeGcu.png"></a></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 测试打通tomcat01到mynet</span></span><br><span class="line">[root@localhost ~]# docker network connect mynet 65b63f9e8fc5</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 连通之后，就是讲tomcat01放到mynet⽹络下（⼀个容器两个ip）</span> </span><br><span class="line"><span class="meta">#</span><span class="bash"> 阿⾥云服务器 ⼀个公⽹ip ⼀个私⽹ip</span></span><br></pre></td></tr></table></figure>

<img src="https://www.z4a.net/images/2021/07/17/image-20210715205317681.png" class="lazyload placeholder" data-srcset="https://www.z4a.net/images/2021/07/17/image-20210715205317681.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="image-20210715205317681.png" border="0" />

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> tomcat01能够连通</span></span><br><span class="line">[root@localhost ~]# docker exec tpmcat01 ping tomcat-net-01</span><br><span class="line">PING tomcat-net-01 (192.168.0.4) 56(84) bytes of data.</span><br><span class="line">64 bytes from tomcat-net-01.mynet (192.168.0.4): icmp_seq=1 ttl=64 time=0.145ms</span><br><span class="line">64 bytes from tomcat-net-01.mynet (192.168.0.4): icmp_seq=2 ttl=64 time=0.079ms</span><br><span class="line">64 bytes from tomcat-net-01.mynet (192.168.0.4): icmp_seq=3 ttl=64 time=0.132ms</span><br></pre></td></tr></table></figure>

<p>假设要跨⽹络操作别⼈，就需要docker network connect 连通！！</p>
<h4 id="redis集群部署"><a href="#redis集群部署" class="headerlink" title="redis集群部署"></a>redis集群部署</h4><img src="https://www.z4a.net/images/2021/07/17/image-20210716111551915.png" class="lazyload placeholder" data-srcset="https://www.z4a.net/images/2021/07/17/image-20210716111551915.png" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="image-20210716111551915.png" border="0" />

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 创建⽹卡</span></span><br><span class="line">docker network create redis --subnet 172.38.0.0/16</span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 部署6个redis集群的脚本</span></span><br><span class="line">for port in $(seq 1 6); \</span><br><span class="line"><span class="meta">&gt;</span><span class="bash"> <span class="keyword">do</span> \</span></span><br><span class="line"><span class="bash">&gt; mkdir -p /mydata/redis/node-<span class="variable">$&#123;port&#125;</span>/conf</span></span><br><span class="line"><span class="meta">&gt;</span><span class="bash"> touch /mydata/redis/node-<span class="variable">$&#123;port&#125;</span>/conf/redis.conf</span></span><br><span class="line"><span class="meta">&gt;</span><span class="bash"> cat &lt;&lt; <span class="string">EOF &gt;/mydata/redis/node-$&#123;port&#125;/conf/redis.conf</span></span></span><br><span class="line"><span class="meta">&gt;</span><span class="bash"><span class="string"> port 6379</span></span></span><br><span class="line"><span class="meta">&gt;</span><span class="bash"><span class="string"> bind 0.0.0.0</span></span></span><br><span class="line"><span class="meta">&gt;</span><span class="bash"><span class="string"> cluster-enabled yes</span></span></span><br><span class="line"><span class="meta">&gt;</span><span class="bash"><span class="string"> cluster-config-file nodes.conf</span></span></span><br><span class="line"><span class="meta">&gt;</span><span class="bash"><span class="string"> cluster-node-timeout 5000</span></span></span><br><span class="line"><span class="meta">&gt;</span><span class="bash"><span class="string"> cluster-announce-ip 172.38.0.1$&#123;port&#125;</span></span></span><br><span class="line"><span class="meta">&gt;</span><span class="bash"><span class="string"> cluster-announce-port 6379</span></span></span><br><span class="line"><span class="meta">&gt;</span><span class="bash"><span class="string"> cluster-announce-bus-port 16379</span></span></span><br><span class="line"><span class="meta">&gt;</span><span class="bash"><span class="string"> appendonly yes</span></span></span><br><span class="line"><span class="meta">&gt;</span><span class="bash"><span class="string"> EOF</span></span></span><br><span class="line"><span class="meta">&gt;</span><span class="bash"> <span class="keyword">done</span></span></span><br><span class="line"></span><br><span class="line">docker run -p 637$&#123;port&#125;:6379 -p 1637$&#123;port&#125;:16379 --name redis-$&#123;port&#125; \</span><br><span class="line">-v /mydata/redis/node-$&#123;port&#125;/data:/data \</span><br><span class="line">-v /mydata/redis/node-$&#123;port&#125;/conf/redis.conf:/etc/redis/redis.conf \</span><br><span class="line">-d --net redis -ip 172.38.0.1$&#123;port&#125; redis:5.0.9-alpine3.11 redis-serve /etc/redis/redis.conf;\</span><br><span class="line"></span><br><span class="line">docker run -p 6371:6379 -p 16371:16379 --name redis-1\</span><br><span class="line">-v /mydata/redis/node-1/data:/data \</span><br><span class="line">-v /mydata/redis/node-1/conf/redis.conf:/etc/redis/redis.conf \</span><br><span class="line">-d --net redis -ip 172.38.0.11 redis:5.0.9 redis-serve /etc/redis/redis.conf</span><br></pre></td></tr></table></figure>

<h2 id="SpringBoot微服务打包成Docker镜像"><a href="#SpringBoot微服务打包成Docker镜像" class="headerlink" title="SpringBoot微服务打包成Docker镜像"></a>SpringBoot微服务打包成Docker镜像</h2><ol>
<li>构建springboot项目</li>
<li>打包应用</li>
<li>编写dockerfile</li>
<li>构建镜像</li>
<li>发布运行</li>
</ol>
<p>以后我们使用了Dokcer之后,给别人交付的就是一个 镜像即可!</p>
<p>到了这里已经完全够用</p>
<p>预告:如果有很多镜像，??  100个镜像?</p>

      </div>
      <div class="post-tags-categories">
        
        <div class="tags">
          
            <a href="/tags/Docker/" class="">
              Docker
            </a>
          
        </div>
        
      </div>
      
        <div class="copyright">
  <ul class="post-copyright">
    <li class="post-copyright-author">
    <strong>作者:  </strong>阳阳</a>
    </li>
    <li class="post-copyright-link">
    <strong>文章链接:  </strong>
    <a href="/2021/07/12/2021-07-12-docker/" target="_blank" title="Docker">https://yangyang-linux.gitee.io/2021/07/12/2021-07-12-docker/</a>
    </li>
    <li class="post-copyright-license">
      <strong>版权声明:   </strong>
      本网站所有文章除特别声明外,均采用 <a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">CC BY-NC-ND 4.0</a>
      许可协议。转载请注明出处!
    </li>
  </ul>
<div>
      
    </article>
    <!-- 上一篇文章和下一篇文章 -->
    
      <!-- 文章详情页的上一页和下一页 -->
<div class="post-nav">



  
  <div class="post-nav-prev post-nav-item">
    <div class="post-nav-img" style="background-size: cover; 
      background-position: center center;">
      <img class="lazyload lazyload placeholder" src="/medias/10.jpg" class="lazyload placeholder" data-srcset="/medias/10.jpg" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="">
    </div>
    <a href="/2021/07/12/2021-07-12-xin-xi-shou-ji/" class="post-nav-link">
      <div class="title">
        <i class="fas fa-angle-left"></i> 上一篇:
        <div class="title-text">信息收集</div>
      </div>
      
      <!-- <div class="content">
        前言&emsp;&emsp;进行渗透测试之前，最重要的一步就是信息收集。在这个阶段，我们要尽可能地收集目标的信息。所谓“
      </div> -->
    </a>
  </div>



  
  <div class="post-nav-next post-nav-item">
    <div class="post-nav-img" style="background-size: cover; 
      background-position: center center;">
      <img class="lazyload lazyload placeholder" src="/medias/11.jpg" class="lazyload placeholder" data-srcset="/medias/11.jpg" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" src="" alt="">
    </div>
    <a href="/2021/07/10/2021-07-10-windows-ji-chu-zhi-ling-jin-jie/" class="post-nav-link">
      <div class="title">
        下一篇: <i class="fas fa-angle-right"></i>
        <div class="title-text">Windows 基础指令进阶</div>
      </div>
      <!-- <div class="content">
        一、网络相关指令1ipconfig -------------------- 查看本机ip


1ipconfig /a
      </div> -->
    </a>
  </div>

</div>

    
    

    <!-- 打赏 -->
    
      <div id="appDonate" class="post-donate">
  <div id="donate_board" class="donate_bar center" ref="donate">
    <a id="btn_donate" class="btn_donate" href="javascript:;" title="打赏" @click="showDialogDrawer()"></a>
  </div>
  <transition name="fade">
    <div 
      class="donate-box-mask"
      v-cloak 
      v-show="visible"
      @click="cancelDialogDrawer()"
    >
    </div>
  </transition>
  <transition name="bounce">
    <div class="donate-box" v-cloak v-show="visible">
      <div class="donate-box_close">
        <i class="fas fa-times" aria-hidden="true" @click="cancelDialogDrawer" pointer></i>
      </div>
      <div class="donate-box_title">
        <h4>
          你的赏识是我前进的动力
        </h4>
      </div>
      <div class="donate-box_tab">
        <div class="Alipay" pointer :class="{'active': tabActive === 'Alipay'}" @click="changeTabActive('Alipay')">
          支付宝
        </div>
        <div class="WeChatpay" pointer :class="{'active': tabActive === 'WeChatpay'}" @click="changeTabActive('WeChatpay')">
          微信
        </div>
      </div>
      <div class="donate-box_img">
        <div class="AlipayImg" v-show="tabActive === 'Alipay'">
          <img src="/medias/zfb.jpg" class="lazyload placeholder" data-srcset="/medias/zfb.jpg" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="支付宝打赏" />
        </div> 
        <div class="WeChatpayImg" v-show="tabActive === 'WeChatpay'">
          <img src="/medias/wx.jpg" class="lazyload placeholder" data-srcset="/medias/wx.jpg" srcset="https://img10.360buyimg.com/ddimg/jfs/t1/157667/29/9156/134350/603c6445Ebbc9cabe/41219c5d36d45072.gif" alt="微信打赏" />
        </div>
      </div>
    </div>
  </transition>
</div>

<script>
  var body = document.body || document.documentElement || window;
  var vm = new Vue({
    el: '#appDonate',
    data: {
      visible: false,
      tabActive: 'Alipay',
      top: 0,
    },
    computed: {
    },
    mounted() {
    },
    methods: {
      showDialogDrawer() {
        this.visible = true;
        // 防止页面滚动，只能让弹框滚动
        // function getScroll() {
        //   return {
        //     left: window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0,
        //     top: window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0
        //   };
        // }
        this.top = $(document).scrollTop() // or getScroll().top
        // console.log('aa', $('.main-content'));
        body.style.cssText = 'overflow: hidden;';
      },
      cancelDialogDrawer() {
        this.visible = false;
        body.removeAttribute('style');
        $(document).scrollTop(this.top)
      },
      changeTabActive(name) {
        this.tabActive = name;
      }
    },
    created() {}
  })
</script>
    

    <!-- 分享 -->
    
      <!-- https://github.com/overtrue/share.js -->
<!-- 文章详情页的分享 -->
<div class="social-share" data-sites="twitter,facebook,google,qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>

<script src="/js/shareJs/social-share.min.js"></script>
</script>

<style>
  .social-share {
    margin: 20px 0;
  }
</style>


    
    
    <!-- 评论 -->
    <!-- 评论 -->

  <div id="myComment">
    
      
<section id="comments" style="padding: 1em; margin: 15px auto;"
	class="animated bounceInUp">
	<div id="vcomment" class="comment"></div>
</section>
<style>
	#comments {
		background: rgba(255,255,255,0.9);
	}
	#veditor {
		background-image: url('https://img.zcool.cn/community/01a253594c71cfa8012193a329a77f.gif');
		background-size: contain;
		background-repeat: no-repeat;
		background-position: right;
		background-color: rgba(255, 255, 255, 0);
		resize: vertical;
	}
	#veditor:focus{
		background-position-y: 200px;
		transition: all 0.2s ease-in-out 0s;
	}
	#vcomment .vcards .vcard .vh .vhead .vtag.vvisitor {
		background-color: #42b983;
	}
	.v[data-class=v] .vbtn:active, .v[data-class=v] .vbtn:hover {
		color: #42b983;
		border-color: #42b983;
	}
	#vcomment .vcards .vcard .vhead .vsys i {
		display: none;
	}
	/* 底部valine链接 */
	#vcomment .vpower {
		display: none;
	}
	
	/* 底下注释是修改 名称和邮箱和网址输入框的样式 */
	/* #vcomment .vheader {
		display: flex;
		justify-content: space-around;
	}
	
	#vcomment .vheader .vnick {
		width: 31%;
		border: 2px solid #dedede;
		padding-left: 10px;
		padding-right: 10px;
		border-radius: 5px
	}

	#vcomment .vheader .vmail {
		width: 31%;
		border: 2px solid #dedede;
		padding-left: 10px;
		padding-right: 10px;
		border-radius: 5px
	}

	#vcomment .vheader .vlink {
		width: 31%;
		border: 2px solid #dedede;
		padding-left: 10px;
		padding-right: 10px;
		border-radius: 5px
	} */

	img.vimg {
		transition: all 1s;
		/* 头像旋转时间为 1s */
	}

	img.vimg:hover {
		transform: rotate(360deg);
		-webkit-transform: rotate(360deg);
		-moz-transform: rotate(360deg);
		-o-transform: rotate(360deg);
		-ms-transform: rotate(360deg);
	}

	#vcomment .vcards .vcard {
		padding: 15px 20px 0 20px;
		border-radius: 10px;
		margin-bottom: 15px;
		box-shadow: 0 0 4px 1px rgba(0, 0, 0, .12);
		transition: all .3s
	}

	#vcomment .vcards .vcard:hover {
		box-shadow: 0 0 8px 3px rgba(0, 0, 0, .12)
	}

	#vcomment .vcards .vcard .vh .vcard {
		border: none;
		box-shadow: none;
	}
</style>
    
  </div>

<!-- comment script in themes\hexo-theme-bamboo\layout\_partial\scripts\index.ejs -->


  </div>

  <!-- 目录 -->
  <!-- 文章详情页右侧目录 -->

  <div class="toc-aside">
    <div class="toc-main">
      <div class="toc-aside-title">
        <i class="fas fa-list-ul" aria-hidden="true"></i><span>本文目录</span>
        
          <div class="toc-open-close">本文目录</div>
        
      </div>
      <div class="toc-content">
        <div class="toc"></div>
      </div>
    </div>
  </div>

  <!-- 手机端目录按钮 -->
  <div id="toc-mobile-btn">
    <i class="fas fa-list-ul" aria-hidden="true"></i>
  </div>


<script>
  function closeToc(init) {
    $(".toc-aside").css({'width': 0, 'padding': 0, 'transition': init ?  'noe' : 'width 0.3s' });
    $(".toc-content").css({'width': 0});
    $(".toc-aside-title span, .toc-aside-title i").css({'display': 'none'});
    $(".main-content").css({'width': '75%', 'margin': '10px auto'});
  };
  function openToc() {
    $(".main-content").css({'width': '65%', 'margin-right': '10px', 'margin-left': 'calc(35% - 350px)'});
    $(".toc-aside").css({'width': '300px', 'padding': '0 10px', 'transition': 'width 0.3s'});
    $(".toc-content").css({'width': '300px'});
    $(".toc-aside-title span, .toc-aside-title i").css({'display': 'inline-block'});
  }
  function openBtnClickFn () {
    let openOrCloseBtn = $('.toc-aside .toc-aside-title .toc-open-close');
    let open = eval('' || 'false');
    openOrCloseBtn.click(function() {
      if (open) {
        closeToc();
        open = false;
      } else {
        openToc();
        open = true;
      }
    });
  };
  openBtnClickFn();
  initCloseTocWidth(true);

  function initCloseTocWidth(init) {
    if (window.innerWidth >= 992) {
      let isClose = true;
      isClose && closeToc(init)
    }
  }

  document.addEventListener('pjax:complete', function () {
    $(".toc-aside").css({'transition': 'no'});
  })
  document.addEventListener('pjax:complete', function () {
    openBtnClickFn();
  })
  
</script>

  <!-- 图片放大 Wrap images with fancybox support -->
  <script src="/js/wrapImage.js"></script>
</div>

<!-- 文章详情页背景图 -->
<div id="appBgSwiper" style="position: fixed;left: 0;top: 0;width: 100%;height: 100%;z-index: -2;"
	:style="{'background-color': bgColor ? bgColor : 'transparent'}">
	<transition-group tag="ul" :name="names">
		<li v-for='(image,index) in img' :key='index' v-show="index === mark" class="bg-swiper-box">
			<img :src="image" class="bg-swiper-img no-lazy">
		</li>
	</transition-group>
</div>
<script>
	var vm = new Vue({
		el: '#appBgSwiper',
		data: {
			names: '' || 'fade' || 'fade', // translate-fade fade
			mark: 0,
			img: [],
			bgColor: '',
			time: null
		},
		methods: {   //添加方法
			change(i, m) {
				if (i > m) {
					// this.names = 'fade';
				} else if (i < m) {
					// this.names = 'fade';
				} else {
					return;
				}
				this.mark = i;
			},
			prev() {
				// this.names = 'fade';
				this.mark--;
				if (this.mark === -1) {
					this.mark = 3;
					return
				}
			},
			next() {
				// this.names = 'fade';
				this.mark++;
				if (this.mark === this.img.length) {
					this.mark = 0;
					return
				}
			},
			autoPlay() {
				// this.names = 'fade';
				this.mark++;
				if (this.mark === this.img.length) {
					this.mark = 0;
					return
				}
			},
			play() {
				let bgImgDelay = '' || '180000'
				let delay = parseInt(bgImgDelay) || 180000;
				this.time = setInterval(this.autoPlay, delay);
			},
			enter() {
				clearInterval(this.time);
			},
			leave() {
				this.play();
			}
		},
		created() {
			this.play()
		},
		beforeDestroy() {
			clearInterval(this.time);
		},
		mounted() {
			let prop = '' || 'https://pic4.zhimg.com/80/v2-5030587bac1b856d09e0a119ff6d7c04_1440w.jpg,https://api.btstu.cn/sjbz/api.php';
			let isImg = prop.includes('.bmp') || prop.includes('.jpg') || prop.includes('.png') || prop.includes('.tif') || prop.includes('.gif') || prop.includes('.pcx') || prop.includes('.tga') || prop.includes('.exif') || prop.includes('.fpx') || prop.includes('.psd') || prop.includes('.cdr') || prop.includes('.pcd') || prop.includes('.dxf') || prop.includes('.ufo') || prop.includes('.eps') || prop.includes('.ai') || prop.includes('.raw') || prop.includes('.WMF') || prop.includes('.webp') || prop.includes('.jpeg') || prop.includes('http://') || prop.includes('https://')
			if (isImg) {
				let img = prop.split(',');
				let configRoot = '/'
				let arrImg = [];
				img.forEach(el => {
					var Expression = /http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
					var objExp = new RegExp(Expression);

					if (objExp.test(el)) {
						// http or https
						arrImg.push(el);
					} else {
						// 非http or https开头
						// 本地文件
						let firstStr = el.charAt(0);
						if (firstStr == '/') {
							el = el.substr(1); // 删除第一个字符 '/',因为 configRoot最后一个字符为 /
						}
						el = configRoot + el;
						arrImg.push(el);
					}
				})
				this.img = arrImg;
			} else {
				this.bgColor = prop;
			}
		}
	})
</script>

<style>
	.bg-swiper-box {
		position: absolute;
		display: block;
		width: 100%;
		height: 100%;
	}

	.bg-swiper-img {
		object-fit: cover;
		width: 100%;
		height: 100%;
	}
</style>




  <script>
  function loadMermaid() {
    if (document.getElementsByClassName('mermaid').length) {
      if (window.mermaidJsLoad) mermaid.init()
      else {
        loadScript('https://cdnjs.cloudflare.com/ajax/libs/mermaid/8.6.3/mermaid.min.js').then(() => {
          window.mermaidJsLoad = true
          mermaid.initialize({
            theme: 'default',
          })
          if ('true') {
            mermaid.init();
          }
        })
      }
    }
  };
  document.addEventListener("DOMContentLoaded", function () {
    loadMermaid();
  })

  document.addEventListener('pjax:complete', function () {
    loadMermaid();
  })
  
</script>


      </main>
    </div>

    <!-- 页脚 -->
    
  
  <!-- 底部鱼儿跳动效果，依赖于jquery-->
<div id="j-fish-skip" style=" position: relative;height: 153px;width: auto;"></div>
<script>
  var RENDERER = {
    POINT_INTERVAL: 5,
    FISH_COUNT: 3,
    MAX_INTERVAL_COUNT: 50,
    INIT_HEIGHT_RATE: .5,
    THRESHOLD: 50,
    FISH_COLOR: '',
    init: function () {
      this.setFishColor(); this.setParameters(), this.reconstructMethods(), this.setup(), this.bindEvent(), this.render()
    },
    setFishColor: function () {
      let isDark = JSON.parse(localStorage.getItem('dark')) || JSON.parse('false');
      if (isDark) {
        this.FISH_COLOR = '#222'; // 暗黑色，有时间把这整成一个变量
      } else {
        this.FISH_COLOR = '' || '#42b983';
      }
    },
    setParameters: function () {
      this.$window = $(window), this.$container = $("#j-fish-skip"), this.$canvas = $("<canvas />"), this.context = this.$canvas.appendTo(this.$container).get(0).getContext("2d"), this.points = [], this.fishes = [], this.watchIds = []
    },
    createSurfacePoints: function () {
      var t = Math.round(this.width / this.POINT_INTERVAL);
      this.pointInterval = this.width / (t - 1), this.points.push(new SURFACE_POINT(this, 0));
      for (var i = 1; i < t; i++) {
        var e = new SURFACE_POINT(this, i * this.pointInterval),
          h = this.points[i - 1];
        e.setPreviousPoint(h), h.setNextPoint(e), this.points.push(e)
      }
    },
    reconstructMethods: function () {
      this.watchWindowSize = this.watchWindowSize.bind(this), this.jdugeToStopResize = this.jdugeToStopResize.bind(this), this.startEpicenter = this.startEpicenter.bind(this), this.moveEpicenter = this.moveEpicenter.bind(this), this.reverseVertical = this.reverseVertical.bind(this), this.render = this.render.bind(this)
    },
    setup: function () {
      this.points.length = 0, this.fishes.length = 0, this.watchIds.length = 0, this.intervalCount = this.MAX_INTERVAL_COUNT, this.width = this.$container.width(), this.height = this.$container.height(), this.fishCount = this.FISH_COUNT * this.width / 500 * this.height / 500, this.$canvas.attr({
        width: this.width,
        height: this.height
      }), this.reverse = !1, this.fishes.push(new FISH(this)), this.createSurfacePoints()
    },
    watchWindowSize: function () {
      this.clearTimer(), this.tmpWidth = this.$window.width(), this.tmpHeight = this.$window.height(), this.watchIds.push(setTimeout(this.jdugeToStopResize, this.WATCH_INTERVAL))
    },
    clearTimer: function () {
      for (; this.watchIds.length > 0;) clearTimeout(this.watchIds.pop())
    },
    jdugeToStopResize: function () {
      var t = this.$window.width(),
        i = this.$window.height(),
        e = t == this.tmpWidth && i == this.tmpHeight;
      this.tmpWidth = t, this.tmpHeight = i, e && this.setup()
    },
    bindEvent: function () {
      this.$window.on("resize", this.watchWindowSize), this.$container.on("mouseenter", this.startEpicenter), this.$container.on("mousemove", this.moveEpicenter)
    },
    getAxis: function (t) {
      var i = this.$container.offset();
      return {
        x: t.clientX - i.left + this.$window.scrollLeft(),
        y: t.clientY - i.top + this.$window.scrollTop()
      }
    },
    startEpicenter: function (t) {
      this.axis = this.getAxis(t)
    },
    moveEpicenter: function (t) {
      var i = this.getAxis(t);
      this.axis || (this.axis = i), this.generateEpicenter(i.x, i.y, i.y - this.axis.y), this.axis = i
    },
    generateEpicenter: function (t, i, e) {
      if (!(i < this.height / 2 - this.THRESHOLD || i > this.height / 2 + this.THRESHOLD)) {
        var h = Math.round(t / this.pointInterval);
        h < 0 || h >= this.points.length || this.points[h].interfere(i, e)
      }
    },
    reverseVertical: function () {
      this.reverse = !this.reverse;
      for (var t = 0, i = this.fishes.length; t < i; t++) this.fishes[t].reverseVertical()
    },
    controlStatus: function () {
      for (var t = 0, i = this.points.length; t < i; t++) this.points[t].updateSelf();
      for (t = 0, i = this.points.length; t < i; t++) this.points[t].updateNeighbors();
      this.fishes.length < this.fishCount && 0 == --this.intervalCount && (this.intervalCount = this.MAX_INTERVAL_COUNT, this.fishes.push(new FISH(this)))
    },
    render: function () {
      requestAnimationFrame(this.render), this.controlStatus(), this.context.clearRect(0, 0, this.width, this.height), this.context.fillStyle = this.FISH_COLOR;
      for (var t = 0, i = this.fishes.length; t < i; t++) this.fishes[t].render(this.context);
      this.context.save(), this.context.globalCompositeOperation = "xor", this.context.beginPath(), this.context.moveTo(0, this.reverse ? 0 : this.height);
      for (t = 0, i = this.points.length; t < i; t++) this.points[t].render(this.context);
      this.context.lineTo(this.width, this.reverse ? 0 : this.height), this.context.closePath(), this.context.fill(), this.context.restore()
    }
  },
  SURFACE_POINT = function (t, i) {
    this.renderer = t, this.x = i, this.init()
  };
  SURFACE_POINT.prototype = {
    SPRING_CONSTANT: .03,
    SPRING_FRICTION: .9,
    WAVE_SPREAD: .3,
    ACCELARATION_RATE: .01,
    init: function () {
      this.initHeight = this.renderer.height * this.renderer.INIT_HEIGHT_RATE, this.height = this.initHeight, this.fy = 0, this.force = {
        previous: 0,
        next: 0
      }
    },
    setPreviousPoint: function (t) {
      this.previous = t
    },
    setNextPoint: function (t) {
      this.next = t
    },
    interfere: function (t, i) {
      this.fy = this.renderer.height * this.ACCELARATION_RATE * (this.renderer.height - this.height - t >= 0 ? -1 : 1) * Math.abs(i)
    },
    updateSelf: function () {
      this.fy += this.SPRING_CONSTANT * (this.initHeight - this.height), this.fy *= this.SPRING_FRICTION, this.height += this.fy
    },
    updateNeighbors: function () {
      this.previous && (this.force.previous = this.WAVE_SPREAD * (this.height - this.previous.height)), this.next && (this.force.next = this.WAVE_SPREAD * (this.height - this.next.height))
    },
    render: function (t) {
      this.previous && (this.previous.height += this.force.previous, this.previous.fy += this.force.previous), this.next && (this.next.height += this.force.next, this.next.fy += this.force.next), t.lineTo(this.x, this.renderer.height - this.height)
    }
  };
  var FISH = function (t) {
    this.renderer = t, this.init()
  };
  FISH.prototype = {
    GRAVITY: .4,
    init: function () {
      this.direction = Math.random() < .5, this.x = this.direction ? this.renderer.width + this.renderer.THRESHOLD : -this.renderer.THRESHOLD, this.previousY = this.y, this.vx = this.getRandomValue(4, 10) * (this.direction ? -1 : 1), this.renderer.reverse ? (this.y = this.getRandomValue(1 * this.renderer.height / 10, 4 * this.renderer.height / 10), this.vy = this.getRandomValue(2, 5), this.ay = this.getRandomValue(.05, .2)) : (this.y = this.getRandomValue(6 * this.renderer.height / 10, 9 * this.renderer.height / 10), this.vy = this.getRandomValue(-5, -2), this.ay = this.getRandomValue(-.2, -.05)), this.isOut = !1, this.theta = 0, this.phi = 0
    },
    getRandomValue: function (t, i) {
      return t + (i - t) * Math.random()
    },
    reverseVertical: function () {
      this.isOut = !this.isOut, this.ay *= -1
    },
    controlStatus: function (t) {
      this.previousY = this.y, this.x += this.vx, this.y += this.vy, this.vy += this.ay, this.renderer.reverse ? this.y > this.renderer.height * this.renderer.INIT_HEIGHT_RATE ? (this.vy -= this.GRAVITY, this.isOut = !0) : (this.isOut && (this.ay = this.getRandomValue(.05, .2)), this.isOut = !1) : this.y < this.renderer.height * this.renderer.INIT_HEIGHT_RATE ? (this.vy += this.GRAVITY, this.isOut = !0) : (this.isOut && (this.ay = this.getRandomValue(-.2, -.05)), this.isOut = !1), this.isOut || (this.theta += Math.PI / 20, this.theta %= 2 * Math.PI, this.phi += Math.PI / 30, this.phi %= 2 * Math.PI), this.renderer.generateEpicenter(this.x + (this.direction ? -1 : 1) * this.renderer.THRESHOLD, this.y, this.y - this.previousY), (this.vx > 0 && this.x > this.renderer.width + this.renderer.THRESHOLD || this.vx < 0 && this.x < -this.renderer.THRESHOLD) && this.init()
    },
    render: function (t) {
      t.save(), t.translate(this.x, this.y), t.rotate(Math.PI + Math.atan2(this.vy, this.vx)), t.scale(1, this.direction ? 1 : -1), t.beginPath(), t.moveTo(-30, 0), t.bezierCurveTo(-20, 15, 15, 10, 40, 0), t.bezierCurveTo(15, -10, -20, -15, -30, 0), t.fill(), t.save(), t.translate(40, 0), t.scale(.9 + .2 * Math.sin(this.theta), 1), t.beginPath(), t.moveTo(0, 0), t.quadraticCurveTo(5, 10, 20, 8), t.quadraticCurveTo(12, 5, 10, 0), t.quadraticCurveTo(12, -5, 20, -8), t.quadraticCurveTo(5, -10, 0, 0), t.fill(), t.restore(), t.save(), t.translate(-3, 0), t.rotate((Math.PI / 3 + Math.PI / 10 * Math.sin(this.phi)) * (this.renderer.reverse ? -1 : 1)), t.beginPath(), this.renderer.reverse ? (t.moveTo(5, 0), t.bezierCurveTo(10, 10, 10, 30, 0, 40), t.bezierCurveTo(-12, 25, -8, 10, 0, 0)) : (t.moveTo(-5, 0), t.bezierCurveTo(-10, -10, -10, -30, 0, -40), t.bezierCurveTo(12, -25, 8, -10, 0, 0)), t.closePath(), t.fill(), t.restore(), t.restore(), this.controlStatus(t)
    }
  }, $(function () {
    RENDERER.init()
    $('.dark').click(function () {
      setTimeout(() => {
        RENDERER.setFishColor();
        RENDERER.context.fill();
      });
    })
  });
</script>
  <div class="footer bg-color">
    <div class="footer-main">
      
        
          <div class="link">
            
              
                <a href="mailto:2985409357@qq.com" class="social">
                  
                    <i class="fa fa-envelope" aria-hidden="true"></i>
                  
                </a>
              
            
              
                <a target="_blank" rel="noopener" href="https://github.com/yangyang-linux" class="social">
                  
                    <i class="fab fa-github" aria-hidden="true"></i>
                  
                </a>
              
            
              
                <a href="tencent://AddContact/?fromId=50&amp;fromSubId=1&amp;subcmd=all&amp;uin=2985409357" class="social">
                  
                    <i class="fab fa-qq" aria-hidden="true"></i>
                  
                </a>
              
            
          </div>
        
      
        
          <div class="footer-copyright">
            <p>Copyright © 2019 - <span id="display_copyright_time"></span> <a target="_blank" rel="noopener" href="https://gitee.com/yangyang-linux">yangyang-linux</a> | Powered by <a target="_blank" rel="noopener" href="https://hexo.io/zh-cn/docs/">Hexo</a> | Theme <a target="_blank" rel="noopener" href="https://github.com/yuang01/theme">Bamboo</a></p>

          </div>
        
      
        
          
            <!-- 不蒜子统计 -->
            <!-- 不蒜子统计 -->
<span id="busuanzi_container_site_pv">
      <i class="fas fa-eye" aria-hidden="true"></i>本站总访问量：<span id="busuanzi_value_site_pv"></span> 次
</span>
<span class="post-meta-divider">|</span>
<span id="busuanzi_container_site_uv" style='display:none'>
      <i class="fas fa-users" aria-hidden="true"></i>本站访客数：<span id="busuanzi_value_site_uv"></span> 人
</span>

          
        
      
        
          <div class="footer-custom">
            
              <div><p><span>本博客已萌萌哒地运行</span><span id="display_live_time"></span></p>
</div>
            
          </div>
        
      
		</br>
		</br>
		</br>
    </div>
  </div>



    <!-- 渲染暗黑按钮 -->
    
      <div class="dark">
  <div class="dark-content">
    <i class="fas fa-moon" aria-hidden="true"></i>
    <!-- <span>关灯</span> -->
  </div>
  
</div>

<script>
  $(function() {
    let isDark = JSON.parse(localStorage.getItem('dark'))  || JSON.parse('false');
    if (isDark) {
      $(".dark-content").replaceWith(
          `
          <div class='dark-content'>
            <i class="fas fa-lightbulb" aria-hidden="true"></i>
          </div>
          `
        );
    }
    $('.dark').click(function() {
      if ($(document.body).is('.darkModel')) {
        $(document.body).removeClass('darkModel');
        localStorage.setItem('dark', false);
        $(".dark-content").replaceWith(
          `
          <div class='dark-content'>
            <i class="fas fa-moon" aria-hidden="true"></i>
          </div>
          `
        );
      } else {
        $(document.body).addClass('darkModel');
        localStorage.setItem('dark', true);
        $(".dark-content").replaceWith(
          `
          <div class='dark-content'>
            <i class="fas fa-lightbulb" aria-hidden="true"></i>
          </div>
          `
        );
      }
    })
  })
</script>
    
    <!-- 渲染回到顶部按钮 -->
    
      <div class="goTop top-btn-color" pointer>
  <i class="fas fa-arrow-up" aria-hidden="true"></i>
</div>
<script src="/js/goTop.js"></script>

    
    <!-- 渲染左下角音乐播放器 -->
    
      <link rel="stylesheet" href="/js/aplayer/APlayer@1.10.1.min.css">
<style>
.aplayer .aplayer-lrc p {
  
  font-size: 12px;
  font-weight: 700;
  line-height: 16px !important;
}

.aplayer .aplayer-lrc p.aplayer-lrc-current {
  
  font-size: 15px;
  color: #C90041;
}


.aplayer.aplayer-fixed.aplayer-narrow .aplayer-body {
  left: -66px !important;
}

.aplayer.aplayer-fixed.aplayer-narrow .aplayer-body:hover {
  left: 0px !important;
}


</style>
<meting-js  
  class=""
  server="netease"
  type="playlist"
  id="5300120281"
  fixed='true'
  autoplay='true'
  theme='#C90041'
  loop='all'
  order='random'
  preload='auto'
  volume='0.4'
  list-folded='true'
>
</meting-js>

<!-- <style>
  #aplayer {
    position: fixed;
    left: 0;
    bottom: 300px;
  }
</style> -->
<script src="https://unpkg.com/aplayer@1.10.1/dist/APlayer.min.js"></script>
<script src="https://unpkg.com/meting@2/dist/Meting.min.js"></script>
    

    <!-- 图片放大 -->
    
      <script src="/js/fancybox/jquery.fancybox.min.js"></script>
    

    <!-- 百度解析 -->
    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <!-- 背景彩带 -->
    
      <script type="text/javascript" size="100" alpha='0.4' zIndex="-1" src="/js/ribbon.min.js"></script>
    

    <script src="/js/utils/index.js"></script>
    <script src="/js/app.js"></script>
    
    <!-- 文章目录所需js -->
<link href="/js/tocbot/tocbot.css" rel="stylesheet">
<script src="/js/tocbot/tocbot.min.js"></script>

<script>
  var headerEl = 'h1, h2, h3, h4, h5, h6',  //headers 
    content = '.post-detail',//文章容器
    idArr = {};  //标题数组以确定是否增加索引id
  //add #id
  var option = {
    // Where to render the table of contents.
    tocSelector: '.toc',
    // Where to grab the headings to build the table of contents.
    contentSelector: content,
    // Which headings to grab inside of the contentSelector element.
    headingSelector: headerEl,
    scrollSmooth: true,
    scrollSmoothOffset: -80,
    headingsOffset: -($(window).height() * 0.4 - 45),
    positionFixedSelector: '.toc-main',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto',
    activeLinkClass: 'is-active-link',
    // onClick: function (e) {},
  }
  if ($('.toc').length > 0) {

    $(content).children(headerEl).each(function () {
      //去除空格以及多余标点
      var headerId = $(this).text().replace(/[\s|\~|`|\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\_|\+|\=|\||\|\[|\]|\{|\}|\;|\:|\"|\'|\,|\<|\.|\>|\/|\?|\：|\，|\。]/g, '');

      headerId = headerId.toLowerCase();
      if (idArr[headerId]) {
        //id已经存在
        $(this).attr('id', headerId + '-' + idArr[headerId]);
        idArr[headerId]++;
      }
      else {
        //id未存在
        idArr[headerId] = 1;
        $(this).attr('id', headerId);
      }
    });

    document.addEventListener("DOMContentLoaded", function () {
      tocbot.init(option);
      mobileTocClick();
    });

  }

  window.tocScrollFn = function () {
    return bamboo.throttle(function () {
      findHeadPosition();
    }, 100)()
  }
  window.addEventListener('scroll', tocScrollFn);

  const findHeadPosition = function (top) {
    if ($('.toc-list').length <= 0) {
      return false;
    }
    setTimeout(() => {  // or DOMContentLoaded 
      autoScrollToc();
    }, 0);
  }

  const autoScrollToc = function () {
    const $activeItem = document.querySelector('.is-active-link');
    const $cardToc = document.querySelector('.toc-content');
    const activePosition = $activeItem.getBoundingClientRect().top
    const sidebarScrollTop = $cardToc.scrollTop
    if (activePosition > (document.documentElement.clientHeight - 100)) {
      $cardToc.scrollTop = sidebarScrollTop + 150
    }
    if (activePosition < 100) {
      $cardToc.scrollTop = sidebarScrollTop - 150
    }
  }

  document.addEventListener('pjax:send', function () {
    if ($('.toc').length) {
      tocbot.destroy();
    }
  });

  document.addEventListener('pjax:complete', function () {
    if ($('.toc').length) {
      tocbot.init(option);
      mobileTocClick();
    }
  });
  
  // 手机端toc按钮点击出现目录
  const mobileTocClick = function () {
    const $cardTocLayout = document.getElementsByClassName('toc-aside')[0];
    const $cardToc = $cardTocLayout.getElementsByClassName('toc-content')[0];
    let right = '45px';
    if (window.innerWidth >= 551 && window.innerWidth <= 992) {
      right = '100px'
    }
    const mobileToc = {
      open: () => {
        $cardTocLayout.style.cssText = 'animation: toc-open .3s; opacity: 1; right: ' + right
      },

      close: () => {
        $cardTocLayout.style.animation = 'toc-close .2s'
        setTimeout(() => {
          $cardTocLayout.style.cssText = "opacity:''; animation: ''; right: ''"
        }, 100)
      }
    }
    document.getElementById('toc-mobile-btn').addEventListener('click', () => {
      if (window.getComputedStyle($cardTocLayout).getPropertyValue('opacity') === '0') mobileToc.open()
      else mobileToc.close()
    })

    $cardToc.addEventListener('click', (e) => {
      if (window.innerWidth < 992) { // 小于992px的时候
        mobileToc.close()
      }
    })
  }
</script>

<style>
  .is-position-fixed {
    position: sticky !important;
    top: 74px;
  }

  .toc-main ul {
    counter-reset: show-list;
  }

  .toc-main ul li::before {
    content: counter(item)".";
    display: block;
    position: absolute;
    left: 12px;
    top: 0;
  }
</style> 

<!-- 设置导航背景 -->
<script>
  let setHeaderClass = () => {
    const headerMenuTransparent = true;
    if (!headerMenuTransparent) { return; }
    const nav = $('#navHeader');
    const navTop = nav.outerHeight();
    const winTop = $(window).scrollTop();
    if(winTop > navTop) {
      nav.addClass('header-bg-color');
    }
    else {
      nav.removeClass('header-bg-color');
    }
  };

  let scrollCollect = () => {
    return bamboo.throttle(function (e) {
      setHeaderClass();
    }, 200)()
  }

  let initHeaderBg = () => {
    setHeaderClass();
  }

  setHeaderClass();
  window.addEventListener('scroll', scrollCollect);

  document.addEventListener('pjax:send', function () {
    window.removeEventListener('scroll', scrollCollect)
  })
  document.addEventListener('pjax:complete', function () {
    window.addEventListener('scroll', scrollCollect);
    setHeaderClass();
  })
</script> 

<!-- 渲染issues标签里的内容 -->
<script>
  function loadIssuesJS() {
    if ($(".post-detail").find(".issues-api").length == 0) {
      return;
    } 
    loadScript('/js/issues/index.js');
  };
  $(function () {
    loadIssuesJS();
  });
  document.addEventListener('pjax:complete', function () {
    if (typeof IssuesAPI == "undefined") {
      loadIssuesJS();
    }
  })
</script>

<!-- 输入框打字特效 -->
<!-- 输入框打字特效 -->

  <script src="/js/activate-power-mode.js"></script>
  <script>
    POWERMODE.colorful = true;  // 打开随机颜色特效
    POWERMODE.shake = false;    // 关闭输入框抖动
    document.body.addEventListener('input', POWERMODE);//监听打字事件
  </script>


<!-- markdown代码一键复制功能 -->

  <link rel="stylesheet" href="https://unpkg.com/v-plugs-ayu/lib/ayu.css">
  <script src="https://unpkg.com/v-plugs-ayu/lib/ayu.umd.min.js"></script>
  <script src="/js/clipboard/clipboard.min.js"></script>
  <div id="appCopy">
  </div>
  <script data-pjax>
    var vm = new Vue({
      el: '#appCopy',
      data: {
      },
      computed: {
      },
      mounted() {
        const that = this;
        var copy = '复制';
        /* code */
        var initCopyCode = function () {
          var copyHtml = '';
          copyHtml += '<button class="btn-copy" data-clipboard-snippet="" style="position:absolute;top:0;right:0;z-index:1;">';
          copyHtml += '<i class="fas fa-copy"></i><span>' + copy + '</span>';
          copyHtml += '</button>';
          $(".post-detail pre").not('.gutter pre').wrap("<div class='codeBox' style='position:relative;width:100%;'></div>")
          $(".post-detail pre").not('.gutter pre').before(copyHtml);
          new ClipboardJS('.btn-copy', {
            target: function (trigger) {
              return trigger.nextElementSibling;
            }
          });
        }
        initCopyCode();
        $('.btn-copy').unbind('click').bind('click', function () {
          doSomething();
        })
        $(document).unbind('keypress').bind('keypress', function (e) {
          if (e.ctrlKey && e.keyCode == 67) {
            doSomething();
          }
        })

        function doSomething() {
          that.$notify({
            title: "成功",
            content: "代码已复制，请遵守相关授权协议。",
            type: 'success'
          })
        }
      },
      methods: {
      },
      created() { }
    })
  </script>
  

<!-- 图片懒加载 -->
<script defer src="https://unpkg.com/vanilla-lazyload@17.1.0/dist/lazyload.min.js"></script>
<script>
  // https://www.npmjs.com/package/vanilla-lazyload
  // Set the options globally
  // to make LazyLoad self-initialize
  window.lazyLoadOptions = {
    elements_selector: ".lazyload",
    threshold: 0
  };
  // Listen to the initialization event
  // and get the instance of LazyLoad
  window.addEventListener(
    "LazyLoad::Initialized",
    function (event) {
      window.lazyLoadInstance = event.detail.instance;
    },
    false
  );
  document.addEventListener('DOMContentLoaded', function () {
    lazyLoadInstance.update();
  });
  document.addEventListener('pjax:complete', function () {
    lazyLoadInstance.update();
  });
</script>


<!-- 卡片滚动动画 -->

    <script type="text/javascript">
  loadScript("https://unpkg.com/scrollreveal@4.0.6/dist/scrollreveal.min.js")
  function pjax_scrollrebeal() {
    ScrollReveal().reveal('.reveal', {
      distance: '120px',
      duration: '400',
      interval: '30',
      scale: '1',
      origin: 'bottom', // 动画开始的方向
      easing: 'ease'
    });
  }
  $(function () {
    var checkScrollReveal = setInterval(function () {
      if ($("#safearea").css("display") != "block") return
      if (typeof ScrollReveal == "undefined") return
      clearInterval(checkScrollReveal)
      pjax_scrollrebeal();
    }, 100)
  });
  document.addEventListener('pjax:complete', function () {
    pjax_scrollrebeal();
  })
</script>
   

<!-- 评论所需js -->

  
    <!-- 弹幕所需的css和js -->
    
  <!-- 弹幕插件 -->
  <link href="/js/danmu/barrager.css" rel="stylesheet">
  <script src="/js/danmu/jquery.barrager.js"></script>

<!-- 具体js，请前往valine/script.ejs查看 -->

    <script>
  var requiredFields = 'nick';
  requiredFields = requiredFields.split(',');
  comment_el = '.comment';
  let looperValine = null;
  load_valine = function () {
    if ($(comment_el).length) {
      var valine = new Valine({
        el: '#vcomment',
        path: window.location.pathname,
        notify: false,
        verify: false,
        app_id: "HvvYcruryPsiW2egxIpRnlKV-gzGzoHsz",
        app_key: "MLKN1tH2RNDMR4e3O9PJgAh5",
        placeholder: "客官，说点什么吧（如果想让我及时收到的话可以连续发送两遍，会触发邮件提醒机制）",
        avatar: "wavatar",
        master: "3d28ff93d17df2e86f7971eda5159791",   //博主邮箱md5
        tagMeta: ["博主","小伙伴","访客"],     //标识字段名
        friends: "8b42635701290c05327f3faba356ce6e",
        metaPlaceholder: { "nick": "昵称/QQ号", "mail": "邮箱" },
        requiredFields: requiredFields,
        enableQQ: true,
      });
      function debounce(fn) {
        var timerID = null
        return function () {
          var arg = arguments[0]   //获取事件
          if (timerID) {
            clearTimeout(timerID)
          }
          timerID = setTimeout(function () {
            fn(arg)              //事件传入函数
          }, 200)
        }
      }
      //查询评论 valine.Q('*').limit(7) -- 查询所有，限制7条, 下面的的代码是查询当前页面
      var themeDanmu = eval('true');
      var themeLoop = eval('false');
      var themeLooperTime = '5000' || 5000;
      var speed = '20' || 20;
      var isBarrager = true;
      if (themeDanmu == true) {
        do_barrager();
        if ($('.danmuBox').length <= 0) {
          $('.navbar').append('<div class="danmuBox"><div class="danmuBtn open"><span class="danmuCircle"></span><span class="danmuText">弹幕</span></div></div>');
        }
        $('.danmuBtn').on('click', debounce(
          function () {
            if ($('.danmuBtn').hasClass('open')) {
              $('.danmuBtn').removeClass('open')
              clearInterval(looperValine);
              $.fn.barrager.removeAll();
            } else {
              $('.danmuBtn').addClass("open");
              do_barrager();
            }
          }
        ))
      }
      function do_barrager() {
        isBarrager && valine.Q(window.location.pathname).find().then(function (comments) {
          // var num = 0; // 可以记录条数，循环调用的时候只取最新的评论放入弹幕中
          var run_once = true;
          var looper_time = themeLooperTime;
          var total = comments.length;
          // var looper = null;
          var index = 0;
          if (total > 0) {
            barrager();
          } else {
            // 当评论数为0的时候，自动关闭弹幕
            // $('.danmuBtn').removeClass('open');
          }
          function barrager() {
            if (run_once) {
              //如果是首次执行,则设置一个定时器,并且把首次执行置为false
              looperValine = setInterval(barrager, looper_time);
              run_once = false;
            }
            var content = comments[index]._serverData.comment;
            var email = comments[index]._serverData.mail;
            var link = comments[index]._serverData.link;
            var newcontent = content.substring(0, 50).replace(/<[^>]+>/g, "");
            //发布一个弹幕
            const item = {
              img: `https://q1.qlogo.cn/g?b=qq&nk=${email}&s=640`, //图片 
              info: newcontent, //文字 
              href: link, //链接 
              close: true, //显示关闭按钮 
              speed: speed, //延迟,单位秒,默认6 
              color: '#fff', //颜色,默认白色 
              old_ie_color: '#000000', //ie低版兼容色,不能与网页背景相同,默认黑色
            }
            $('body').barrager(item);
            //索引自增
            index++;
            //所有弹幕发布完毕，清除计时器。
            if (index == total) {
              clearInterval(looperValine);
              if (themeLoop === true) {
                setTimeout(function () {
                  do_barrager();
                }, 5000);
              } else {
                $('.danmuBtn').removeClass('open');
              }
              return false;
            }

          }
        })
      }
    }
  };
  $(document).ready(load_valine);
  document.addEventListener('pjax:send', function (e) {
    
      $('.danmuBox').length > 0 && $('.danmuBox').remove()
      looperValine && clearInterval(looperValine);
      $.fn.barrager.removeAll();
    
  })
  document.addEventListener('pjax:complete', function () {
    load_valine();
  });
</script>

  


<!-- 鼠标点击特效 -->
<!-- 爱心点击 -->

  
    <script src="/js/cursor/fireworks.js"></script>
  




  <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" data-pjax></script>


    <!-- pjax -->
    

<!-- pjax -->


  <script src="/js/pjax@0.2.8/index.js"></script>
  
    <!-- 样式位于：source/css/_third-party/pjaxanimate.styl -->

<div class="pjax-animate">
  
    <div class="loading-circle"><div id="loader-circle"></div></div>
    <script>
      window.ShowLoading = function() {
        $(".loading-circle").css("display", "block");
      };
      window.HideLoading = function() {
        $(".loading-circle").css("display", "none");
      }
    </script>
  
	<script>
    document.addEventListener('pjax:complete', function () {
      window.HideLoading();
    })
    document.addEventListener('pjax:send', function () {
      window.ShowLoading();
    })
    document.addEventListener('pjax:error', function () {
      window.HideLoading();
    })
	</script>
</div>

  

  <script>
    var pjax = new Pjax({
      elements: 'a[href]:not([href^="#"]):not([href="javascript:void(0)"]):not([no-pjax])',   // 拦截正常带链接的 a 标签
      selectors: ["#pjax-container","title"],                                   // 根据实际需要确认重载区域
      cacheBust: false,   // url 地址追加时间戳，用以避免浏览器缓存
      timeout: 5000
    });

    document.addEventListener('pjax:send', function (e) {

      try {
        var currentUrl = window.location.pathname;
        var targetUrl = e.triggerElement.href;
        var banUrl = [""];
        if (banUrl[0] != "") {
          banUrl.forEach(item => {
            if(currentUrl.indexOf(item) != -1 || targetUrl.indexOf(item) != -1) {
              window.location.href = targetUrl;
            }
          });
        }
      } catch (error) {}

      $(window).unbind('resize');
      $(window).unbind('scroll');
      $(document).unbind('scroll');
      $(document).unbind('click');
      $('body').unbind('click');

    })
    
    document.addEventListener('pjax:complete', function () {
      $('script[data-pjax], .pjax-reload script').each(function () {
        $(this).parent().append($(this).remove());
      });
    });

    document.addEventListener('pjax:error', function (e) {
      window.location.href = e.triggerElement.href;
    })
    
    // 刷新不从顶部开始
    document.addEventListener("DOMContentLoaded", function () {
      history.scrollRestoration = 'auto';
    })
  </script>



  </body>
</html>